R – VBA Word Macro doesnt recognize whitespaces or wildcards

ms-wordvba

I have a VBA Word Macro that gets words from .txt list and color highlight them in a word .doc document.

The problem is that the script ignores whitespaces and wildcards from the .txt list. I insert the word "wit" but it also changes words like witHIN , witCHE, etc.

I tried inserting wildcards in the .txt file, like or using white spaces like " wit ", but it didnt worked. The script ignore the whitespaces and the wildcards.

THE CODE IS HERE: http://pastebin.com/m3e20f932

Melissa.

Best Solution

Maybe you need to add the option .matchWholeWord = True to line 233? If you would rather do it by using whitespace, you could remove the Trim on line 63. If you want to use wildcards, you would need to have .MatchWildcards = True on line 233.

Related Question