Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-16-2022, 02:18 PM
dsrt16 dsrt16 is offline .matchwholeword = true not working Windows 10 .matchwholeword = true not working Office 2013
Novice
.matchwholeword = true not working
 
Join Date: Nov 2022
Posts: 3
dsrt16 is on a distinguished road
Default .matchwholeword = true not working

So I have this code from Allen Wyatt that used to be working just fine, but now it puts even parts of words in red, even though I have set .matchwholeword to true.




So if I have the word "or" on my confusables list, it will put the "or" in the word "color" in red, but I only want the actual word "or" to be in red.


Code:
Sub CompareWordList()
    Dim sCheckDoc As String
    Dim docRef As Document
    Dim docCurrent As Document
    Dim wrdRef As Object

    sCheckDoc = "the path to my confusables.doc"
    Set docCurrent = Selection.Document
    Set docRef = Documents.Open(sCheckDoc)
    docCurrent.Activate

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Font.Color = wdColorRed
        .Replacement.Text = "^&"
        .Forward = True
        .Format = True
        .MatchWholeWord = True
        .MatchCase = False
        .MatchWildcards = False
    End With

    For Each wrdRef In docRef.Words
        If Asc(Left(wrdRef, 1)) > 32 Then
            With Selection.Find
                .Wrap = wdFindContinue
                .Text = wrdRef
                .Execute Replace:=wdReplaceAll
            End With
        End If
    Next wrdRef

    docRef.Close
    docCurrent.Activate
End Sub
It used to work, then it didn't. So I tried moving the .matchwholeword = true to earlier in the with selection find section so it came before the replacement font, but then that caused a different error, highlighting the "for each wrdref line."

Any ideas? I am an editor, and I use this to change words to red that are often confused with other words or often need punctuation with them to help me catch additional errors, but it is distracting to have it put parts of words in red.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
True/False Error DonBerg68 Excel 2 08-30-2019 08:51 PM
.matchwholeword = true not working if true AND nested or? jriker1 Mail Merge 5 10-14-2017 01:11 PM
.matchwholeword = true not working Converting a 1 or 0 into TRUE or FALSE? ayupchap Mail Merge 1 04-25-2017 02:45 PM
True 4:3 background dimensions a_gunslinger PowerPoint 1 11-28-2016 08:22 PM
.matchwholeword = true not working Macro not staying true oluc Word VBA 4 11-21-2010 08:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft