Share via

Word Compile Error:

Anonymous
2023-07-04T22:06:49+00:00

Hello from Steve

I am very sorry for the second post on the same issue

[Previous thread: https://answers.microsoft.com/en-us/msoffice/forum/all/word-highlight-issue/877cd367-6f29-444c-a105-9779155ba54e]

I marked the first post believing it would function.

Objective please is also to Highlight please.

What is required in order for this to function.

Thank you.

.HighlightColorIndex = wdTurquoise.

This is giving me a,

Compile Error:

Method or data member not found.

Sub Colour_Test()

Application.ScreenUpdating = False 

With Selection.Find 

    .ClearFormatting 

    .Replacement.Text = "" 

    .Forward = True 

    .Wrap = wdFindStop 

    .Format = True 

    .MatchCase = False 

    .MatchWholeWord = False 

    .MatchAllWordForms = False 

    .MatchSoundsLike = False 

    .MatchWildcards = True 

    Do 

        .Text = "All\([0-9]{1,}-[0-9]{1,}-[0-9]{1,}-[0-9]{1,}\)" 

        If .Execute Then 

            .Text = "\([0-9]{1,}-[0-9]{1,}-[0-9]{1,}-[0-9]{1,}\)" 

            .Execute 

            With Selection.Font 

                .Bold = True 

                .Color = wdColorBlue 

                .HighlightColorIndex = wdTurquoise 

            End With 

            Selection.MoveDown Unit:=wdLine, Count:=1 

        Else 

            Exit Do 

        End If 

     Loop 

End With 

Application.ScreenUpdating = True 

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2023-07-04T22:51:06+00:00

Hi Steve8d, I'm Femi and I'd be happy to help you with your question. Apologies for the challenge encountered. The error message you're receiving, "Compile Error: Method or data member not found," indicates that the property or method "wdTurquoise" is not recognized by the compiler. This error typically occurs when there is a reference to an undefined constant or object. Kindly try using the modified code below: Sub Colour_Test() Application.ScreenUpdating = False With Selection.Find . ClearFormatting . Replacement.Text = "" . Forward = True . Wrap = wdFindStop . Format = True . MatchCase = False . MatchWholeWord = False . MatchAllWordForms = False . MatchSoundsLike = False . MatchWildcards = True Do . Text = "All([0-9]{1,}-[0-9]{1,}-[0-9]{1,}-[0-9]{1,})" If . Execute Then . Text = "([0-9]{1,}-[0-9]{1,}-[0-9]{1,}-[0-9]{1,})" . Execute With Selection.Font . Bold = True . Color = wdColorBlue . HighlightColorIndex = 3 ' Replace wdTurquoise with its numeric value End With Selection.MoveDown Unit:=wdLine, Count:=1 Else Exit Do End If Loop End With Application.ScreenUpdating = True End Sub

Hope this resolves the issue!

Best Regards, Femi

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2023-07-05T01:51:18+00:00

    Hello Femi

    Firstly thank you for your time on my issue.

    I am getting an

    Compile Error:

    Method or data member not found.

    It highlites the below as shown.

    . HighlightColorIndex =

    However I decided to try another way which is set out below

    Sub Testcolor()

    Application.ScreenUpdating = False

    Do

    Selection.Find.ClearFormatting 
    
    With Selection.Find 
    
        .Text = "All(" 
    
        .Replacement.Text = "" 
    
        .Forward = True 
    
        .Wrap = wdFindStop 
    
        .Format = False 
    
        .MatchCase = True 
    
        .MatchWholeWord = False 
    
        .MatchWildcards = False 
    
        .MatchSoundsLike = False 
    
        .MatchAllWordForms = False 
    
    End With 
    
    Selection.Find.Execute 
    
    If Selection.Find.Found Then 
    
    Selection.MoveRight Unit:=wdCharacter, Count:=1 
    
    Selection.Extend 
    
    With Selection.Find 
    
        .Text = ")" 
    
        .Replacement.Text = "" 
    
        .Forward = True 
    
        .Wrap = wdFindStop 
    
        .Format = False 
    
        .MatchCase = True 
    
        .MatchWholeWord = False 
    
        .MatchWildcards = False 
    
        .MatchSoundsLike = False 
    
        .MatchAllWordForms = False 
    
    End With 
    
    Selection.Find.Execute 
    
    Selection.MoveLeft Unit:=wdCharacter, Count:=1 
    
    Options.DefaultHighlightColorIndex = wdTurquoise 
    
    Selection.Range.HighlightColorIndex = wdTurquoise 
    
    Selection.MoveDown Unit:=wdLine, Count:=1 
    
    End If 
    
    Loop While Selection.Find.Found 
    
    Application.ScreenUpdating = True 
    

    End Sub

    Steve

    Was this answer helpful?

    0 comments No comments