I'm working with large Word documents which consist of text with a variety of formatting, including colours and font-weight. I'm writing a Macro which counts and displays the number of times particular words appear in this document, but I want to only count those occurrences which have particular formatting.
For example, I want to count the number of times the string "if" appears in a document where it is (a) a whole word, (b) in msBlue colour, (c) either begins a line or has only spaces before it, and (d) non-bold. Another example is that I want to find the string "[ADHOC]" where it is (a) a whole word, (b) in msBlue (c) is on a line of its own, and (d) bold. Occurrences of these words with any other formatting should not be counted.
Below is the code I have written so far for the "if" example. This counts the number of occurrences of the word "if" and displays it on the screen.
Any help with this would be appreciated.
Dim ifs As Integer
Do While .Execute(FindText:="if", Forward:=True, Format:=True, _
MatchWholeWord:=True) = True
ifs = ifs + 1
Response = MsgBox("'if' was found" _
& Str$(ifs) & " times.", vbOKOnly)