Solved How to make Word Macro Ignore Case

October 17, 2011 at 11:42:28
Specs: Windows XP
I've copied and modified an MS 2007 Word Macro to count the number of occurrences of a specific word. The problem is that the " If Trim(.Text) " statement seems to be too specific! It only counts "zoo" if it occurs as "zoo"; "Zoo" is not counted.

How do I change the macro to count all occurences of the word, no matter what the case of each letter?

See More: How to make Word Macro Ignore Case

Report •

October 17, 2011 at 12:15:40
✔ Best Answer
Try the UCase function.

I don't do much with Word macros, but in Excel I would use something like:

If UCase(myWord) = "ZOO" then myCount = myCount + 1

Within VBA only (not in the document) UCase will convert all the lowercase letters in the variable myWord to uppercase and then compare the string to ZOO which is already uppercase.

UCase("zoo") = "ZOO"
UCase("ZOO") = "ZOO"
Ucase("Zoo") = "ZOO"

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

October 17, 2011 at 12:29:20
I used the structure and logic of your suggestion to convert all the words I look up to lower case, then compare it to the lower case word -- "zoo". It works! Thanks for your quick, helpful response.

Report •

October 17, 2011 at 12:33:34

Report •

Related Solutions

Ask Question