Hi guys,
I have got a piece of macro code in Word 2002 that uses the find function to search through a word document to locate a particular instance of a font with certain formatting.
The code is going through each story correctly and is finding the font specified on the search form but only highlights the sentence at the top of the document that uses the specific font, even though this font is used in several other places within the same story and in other stories. Has anyone got any ideas why this is not highlighting every occurrence only the first/last found? Or any ideas as to how I can fix it?
The code I am using is below.
Many thanks in advance.
For Each oStory In ActiveDocument.StoryRanges
Set myrange = oStory
myrange.WholeStory
With myrange.Find
'.ClearFormatting
.Font.Name = strFontToFind
.Font.Size = strFontSizeToFind
.Font.Bold = FontBoldIndicator
.Font.Italic = FontItalicIndicator
With .Replacement
'.ClearFormatting
.Highlight = True
End With
Search_Font = myrange.Find.Font.Name
Search_Size = myrange.Find.Font.Size
MsgBox ("Search Font = " & Search_Font)
MsgBox ("Search Size = " & Search_Size)
.Execute FindText:="", ReplaceWith:="", Format:=True
If .Found = True Then
MsgBox "The font has been found and is highlighted in yellow, please remember to use the clear search macro before closing the document to clear the highlighting"
Else
MsgBox "The font could not be found, if you are sure that this font is in the document please retry the search and make sure that you have selected the intended font format details"
End If
End With
Next
I have got a piece of macro code in Word 2002 that uses the find function to search through a word document to locate a particular instance of a font with certain formatting.
The code is going through each story correctly and is finding the font specified on the search form but only highlights the sentence at the top of the document that uses the specific font, even though this font is used in several other places within the same story and in other stories. Has anyone got any ideas why this is not highlighting every occurrence only the first/last found? Or any ideas as to how I can fix it?
The code I am using is below.
Many thanks in advance.
For Each oStory In ActiveDocument.StoryRanges
Set myrange = oStory
myrange.WholeStory
With myrange.Find
'.ClearFormatting
.Font.Name = strFontToFind
.Font.Size = strFontSizeToFind
.Font.Bold = FontBoldIndicator
.Font.Italic = FontItalicIndicator
With .Replacement
'.ClearFormatting
.Highlight = True
End With
Search_Font = myrange.Find.Font.Name
Search_Size = myrange.Find.Font.Size
MsgBox ("Search Font = " & Search_Font)
MsgBox ("Search Size = " & Search_Size)
.Execute FindText:="", ReplaceWith:="", Format:=True
If .Found = True Then
MsgBox "The font has been found and is highlighted in yellow, please remember to use the clear search macro before closing the document to clear the highlighting"
Else
MsgBox "The font could not be found, if you are sure that this font is in the document please retry the search and make sure that you have selected the intended font format details"
End If
End With
Next