• Set Word Manage Styles default properties programatically?

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Set Word Manage Styles default properties programatically?

    Author
    Topic
    #480315

    I’m pretty sure there’s no way to do this, but has anyone figured out a programmatic way to set the default font and paragraph properties that are set on the Manage Styles tab?

    This is NOT the same as the default font you can set elsewhere and that affects the Normal style. This is a different default. I’ve tried doing it with the macro recorder running. That results in an empty macro. I’ve combed the various properties and methods and found nothing that matches. The defaultfont property of the activetemplate is not this one.

    So is this just one of those things that’s not exposed to VBA?

    Thanks,

    Jessica

    Viewing 5 reply threads
    Author
    Replies
    • #1309083

      If you’re talking about the ‘Default Paragraph Font’ character style, I think you can neither set nor return a font property from that style.

      Even though it’s categorized as a character style, the Default Paragraph Font style does not itself contain any font properties. It really functions as a method (“to the selected text, restore font properties as determined by the paragraph style that is applied to the paragraph within which the selected text is contained”).

      Gary

      • #1309088

        No, I’m not talking about that, with which I am familiar.

        This is the active default font formatting you can set in 2007 and up that, separately from the Normal style, is applied as the default to all text in a doc. To see it, go into the Font tab, open the actual Font window, set some characteristics, and click Default. THAT formatting is what I would like to be able to check and change programmatically.

        Thanks,

        Jessica

        • #1309137

          Hi Jessica,

          In Word 2010, I was able to capture setting the Default Paragraph Font through the Font dialog.

          My macro starts by first opening the Normal.dotm template and then running the Font dialog and clicking the Set As Default button. Then save and close Normal.dotm. The surprise is that all it does is change the Normal style’s font. Which apparently changes the Default Paragraph Font. I say “apparently” because I haven’t tested it beyond seeing that my default font is changed the same way as when I go through the Font dialog manually. :rolleyes:

          Code:
          Sub ChangeDefaultFont()
          Documents.Open FileName:=”Normal.dotm”, ConfirmConversions:=False, _
              ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:=””, _
              PasswordTemplate:=””, Revert:=False, WritePasswordDocument:=””, _
              WritePasswordTemplate:=””, Format:=wdOpenFormatAuto, XMLTransform:=””
          With ActiveDocument.Styles(wdStyleNormal).Font
              .Name = “Calibri”
              .Size = 12
          End With
          ActiveDocument.Save
          ActiveDocument.Close
          End Sub

          Does this do what you want to do? Is it possible the DefaultParagraphFont now takes its font from the Normal style?
          Kim :bananas:

          • #1309310

            No, this is a different default. There is a default that is carried in the Normal style, which is the one that can be changed via your macro.

            However, there is a DIFFERENT place to see and set default formatting. To see it in Word 2007 or 2010, select Manage Styles on the styles panel. Click the Set Defaults tab. The defaults you can set there do not seem to be reflected in Normal style. They can be set for the template or the document.

            Either the interface is buggy, or this other default affects things like styles based on no style and the numbers for list styles.

            Thanks,

            Jessica

            • #1309481

              Jessica,

              A couple of posts earlier, you say you’re referring to a default setting in the Font dialog, but here you’re referring to the Set Defaults tab in the Manage Styles dialog. Two different things – at least inasmuch as you can set not just font, but also paragraph formatting properties, in the Set Defaults tab.

              I’d never played around with the Set Defaults tab before, but based on a quick test, it looks like any settings changed there specifically do modify the properties of the Normal style. The reason you see any changes made here, affecting all the other paragraph styles, is that out of the box, all of the other paragraph styles are based on Normal style – so any changes made to Normal style flow through to the others.

              [Open up a new blank document and display the Styles pane. For each of the paragraph styles that appear by default, click on Modify to examine the style properties – they are all based on Normal. Go to the Set Defaults tab in the Manage Styles dialog, and make some obvious changes like setting the font size to 8 pts, set alignment to Center, change space before/after and line spacing. All of the changes you make there, are exactly applied to Normal style. All of the other styles change too, except for those properties of those styles (such as font size for the Heading styles) that have already been defined as being different from Normal style.]

              If that’s the case, then you should just be able to do what you need, by modifying the properties of Normal style, directly. (If I’m missing something else about the behavior of the Set Defaults tab, please clarify further.)

              Gary

            • #1309649

              Yes, I am referring to the one in the Manage Styles tab that includes paragraph formatting as well as font formatting.

              The link seems to work only one way in Word 2010, at least some of the time. None of the time does the link work via VBA.

              If I use, say, Selection.default.SetAsTemplateDefault to set the default font for a template, the default displayed in the Manage Styles Set Defaults tab does not change. The font for Normal style does change.

              Which gets us back to the original position. There seems to be no way to change the defaults shown in the Manage Styles tab via VBA.

              – Jessica

            • #1315454

              I have tried to find a way to change the Defaults via VBA and have had no luck. The document Defaults were new with Word 2007, and it seems that VBA has not caught up. Chaning the attributes of Normal style will indeed cascade to some other styles. But changing the Defaults will ensure that everything is covered. If you change only Normal style, say to Times New Roman, you might still find that footnotes, endnotes and captions appear in Calibiri with the (odd) native Word line spacing. Note, too, that the Defaults are “theme aware”, and that the default font is +Body (meaning that the font morphs as the theme is changed). Themes are a powerful new feature and worth reading about. They are a bit difficult to understand, but Microsoft has a Theme Builder application which can assist. You can block theme changes in a document; this is done through the Manage Styles button. There’s a VBA method, ActiveDocument.RemoveTheme that does exactly what it suggests. Many documents — court documents, for example — would have no need to be theme aware. Themes function across all Office applications. Powerpoint presentations and Excel charts are good examples of where themes are useful.

    • #1309325

      I see now. I, too, was not able to find a way to address that particular dialog.

      What are you trying to accomplish? That is, how is not being able to set this causing an issue? Perhaps there’s another way. For example, with group policy settings?

      Kim

    • #1309408

      One (unsatisfying) way to do this is by using SendKeys to manipulate the dialog as per this example which changes the font to Calibri, the font size to 11pt and the left indent to 1cm

      Code:
      Sub temp1()  With Application.Dialogs(wdDialogStyleManagement)
          SendKeys “%OCalibri%Z11%L1 cm{ENTER}” 
          .Show
        End With
      End Sub

      According to this webpage, there are no enumerated constants you can use to do this in a more elegant way. There may be a method to do this directly without using the dialog but I haven’t gone looking as it sounds like you already had a look.

    • #1309780

      Jessica,

      I think you may be right about this being a flaky feature. I’ve fiddled with it a little bit (clearly not as extensively as you have), including reading the Normal.dotm xml and it doesn’t seem to reflect what’s actually going on in the template and documents.

      I manually set an unusual font in the Manage styles Set Defaults tab and set it for all documents based on this template (Normal.dotm). I then looked in the xml and this unusual font appeared in wordfontTable.xml and wordstyles.xml. However, when I used the code I posted above, it changed Normal back to Calibri and my styles all use that — even styles based on no style. The unusual font is still displayed on the defaults tab of the Manage styles dialog and still appears in the xml… I’m going to leave this odd font in place just in case it pops up during my normal work.

      What this means for your project, I don’t know. It looks as if, even if you could successfully query the settings in that dialog, they might not be accurate anyway.
      Just one of those things that makes me :bananas:. Kim

    • #1309781

      Word has flaky areas? Shocking.

      I’m just going to tell my authors to disregard the Manage Styles default and be done with it. Maybe the next version of Word will fix that area…or just maybe they’ll fix multilevel list styles. I am holding my breath.

      – Jessica

    • #1309788

      LOL!
      :bananas:

    Viewing 5 reply threads
    Reply To: Reply #1315454 in Set Word Manage Styles default properties programatically?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel