Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change font properties (VBA - Word 2000)

    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?

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change font properties (VBA - Word 2000)

    Does changing the font of the Normal (or Body Text or whatever "base" style you use) style work for you?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change font properties (VBA - Word 2000)

    That won't quite work. I wish it was that easy. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    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.

  4. #4
    Star Lounger
    Join Date
    Nov 2001
    Location
    Illinois, USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change font properties (VBA - Word 2000)

    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

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change font properties (VBA - Word 2000)

    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?

    <pre>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</pre>

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

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change font properties (VBA - Word 2000)

    Kevin's suggestion would have worked if styles had been used (sorry for this smart-aleck remark <img src=/S/wink.gif border=0 alt=wink width=15 height=15>).

    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:
    <pre>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</pre>


    (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:
    <pre> Selection.Font.Name = SelFont
    Selection.TypeText text:=ChrW(SelCharNum)</pre>


    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.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Regards, Klaus

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change font properties (VBA - Word 2000)

    Awright Klaus! <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> I think that will be the perfect solution to my problem. The other solutions give me an idea for another project.... Thanks everybody!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •