views:

269

answers:

2

Hi guys,

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.

A: 

You might try adding the MatchWholeWord:=True property to your Execute statement.

Untested, but I believe that will give you the results you want.

cori
Hi Cori, i tried MatchWholeWord=True and it worked, thanks!
Melissa McRoe
+1  A: 

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.

Kinopiko
Kinopiko i tried removing the TRIM and also worked, thanks.But when i tried adding .MatchWildcards = True, and then went to the txt file and inserted <wit> it worked, but instead of replacing every wit word for wit, replaced with <wit>. Why that happened ?Thanks again guys.
Melissa McRoe