none
Searching for a font doesn't work in a macro? RRS feed

  • Question

  • In a Word document with characters in various fonts and some with "Times New Roman" the following macro doesn't find any text.

    Sub test()
    '
    ' test Macro
    ' Trying to find Time New Roman
    
        Selection.HomeKey unit:=wdStory
    
        With Selection.Find
            .ClearFormatting
            .Font.Name = "Times New Roman"
            Debug.Print "Selection.Find.Font.name = " & .Font.Name
            .Text = ""
            .Replacement.ClearFormatting
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = True
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Debug.Print "Selection.Find.Font.name = " & Selection.Find.Font.Name
        Selection.Find.Execute
        Debug.Print "Selection.Find.MatchWildcards = " & Selection.Find.MatchWildcards
        Debug.Print "Selection.Find.Found = " & Selection.Find.Found
    End Sub

    The output when running the macro is:

    Selection.Find.Font.name = 
    Selection.Find.Font.name = 
    Selection.Find.MatchWildcards = False
    Selection.Find.Found = False
    

    With macOS 10.4.4, Word 16.22 (190211)

    Monday, April 1, 2019 10:45 AM