• Change font properties (VBA – Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Change font properties (VBA – Word 2000)

    Author
    Topic
    #362984

    I’m hoping someone can tell me a way to change font properties for the entire active document with certain exceptions. For example, I want to convert all text to Times New Roman — unless it’s in Symbol or WingDings font. Another example, I need all text in 12 point font — unless it’s sub/superscripted, in which case it should be 9 points.

    I’ve got some ideas on how it could be done, but they are not remotely elegant or efficient. Can anyone help me out?

    Viewing 0 reply threads
    Author
    Replies
    • #552600

      Does changing the font of the Normal (or Body Text or whatever “base” style you use) style work for you?

      • #552607

        That won’t quite work. I wish it was that easy. sad

        The documents I’m working on are written in all kinds of “base” fonts (Arial, Arial narrow, Garamond, Times, Courier, etc) — these fonts all need to standardized to Times New Roman. The kicker is that they are scientific articles and are sprinkled here and there are with Symbol and WingDings characters that have to remain in Symbol and WingDings.

        • #552641

          Are the WingDings and Symbol fonts in complete words? You might be able to use the Words collection of the document, something like:

          For Each aword In ActiveDocument.Words
          If aword.Font.Name = “Wingdings” Then
          MsgBox “Leave the Dingbat alone!”
          Else
          aword.Font.Size = 18
          End If

          Next aword

          If the special characters are just individual scattered characters you can use the Characters collection instead… For each aChar in ActiveDocument.Characters …and so forth

        • #552643

          If I have a paragraph that contains a wingding, and I select the paragraph and press Ctrl+spacebar to force the font back to the default paragraph font, the wingding remains unchanged. However, this does wreck the superscripts. On the other hand, if I select the paragraph and apply the font and point size manually, all is fine. Hmmm…

          How about a macro like this?

          Sub BackToDefault()
          Dim para As Paragraph
          For Each para In ActiveDocument.Paragraphs
              With para.Range
                  .Font.Name = ActiveDocument.Styles(.ParagraphFormat.Style).Font.Name
                  .Font.Size = ActiveDocument.Styles(.ParagraphFormat.Style).Font.Size
              End With
          Next
          End Sub

          You would first set the styles to your liking, then run the above to conform the document to the styles.

        • #552645

          Kevin’s suggestion would have worked if styles had been used (sorry for this smart-aleck remark wink).

          Even if no styles are used, symbols from old decorative fonts like Wingdings and Symbol don’t change if they are inserted from the “Insert > Symbol” dialog (“protected” symbols; the font drop-down list doesn’t show the symbol font).

          You only run into problems if they have been inserted by changing the font to the Symbol font and typing the characters on the keyboard (“unprotected” symbols).

          You can “protect” all symbols from decorative fonts (make them behave as if they had been inserted from the Symbol dialog) with the following macro. After you have run the macro, you can change the font to “Times New Roman”, and the symbols won’t change:

          Sub SymbolsProtect()
            Dim SelFont, SelCharNum
            Selection.Find.ClearFormatting
            With Selection.Find
              ' this will find all (protected and unprotected) symbols:
              .text = "[" & ChrW(61472) & "-" & ChrW(61695) & "]"
              .Replacement.text = ""
              .Forward = True
              .Wrap = wdFindContinue
              .Format = False
              .MatchWildcards = True
            End With
            While Selection.Find.Execute
              With Dialogs(wdDialogInsertSymbol)
                SelFont = .Font
                SelCharNum = .CharNum
              End With
              
              Selection.InsertSymbol _
                Font:=SelFont, _
                CharacterNumber:=SelCharNum, _
                Unicode:=True
          
            Wend
          End Sub

          (Once you have protected the symbols, it would still be a very good idea to run jscher2000’s macro to “style” your document/remove manual formatting)

          If you wanted to unprotect all symbols, replace the 4 lines of Selection.InsertSymbol at the end of the macro with:

              Selection.Font.Name = SelFont
              Selection.TypeText text:=ChrW(SelCharNum)

          If you want text in 12pt and superscripts/subscripts in 9 pt, I’d define the paragraph style as 12pt, and define character styles (9pt super-/subscripted) for superscripts/subscripts. Then I’d search for superscripted/subscripted characters and replace with the character styles.

          cheersRegards, Klaus

          • #552686

            Awright Klaus! clapping I think that will be the perfect solution to my problem. The other solutions give me an idea for another project…. Thanks everybody!

    Viewing 0 reply threads
    Reply To: Change font properties (VBA – Word 2000)

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

    Your information: