Question : Need VBA for Word code for AutoOpen, for "Use xyz font if available, else use Arial"

The title says it all: I want to include code in the AutoOpen macro for a document that will go out to other people, specifying that the document use a specified font if the user has the font on his machine, otherwise use Arial font. What is the VBA for Word code that will do this?

Answer : Need VBA for Word code for AutoOpen, for "Use xyz font if available, else use Arial"

Hopefully the following pasted into the document open routine will work for you:

Private Sub Document_Open()
Dim fontname As Variant
Dim fontfound As Boolean
Dim whichfont As String
Dim story As Variant

    whichfont = "rTimes New Roman"
    fontfound = False
    For Each fontname In Application.FontNames
        If fontname = whichfont Then fontfound = True
    Next
    For Each story In ActiveDocument.StoryRanges
        If fontfound Then
            story.Select
            Selection.Font.Name = whichfont
            Selection.Collapse wdstart
        Else
            story.Select
            Selection.Font.Name = "Arial"
            Selection.Collapse wdstart
        End If
    Next
End Sub

Regards
Chris B
Random Solutions  
 
programming4us programming4us