Hi guys,
I have got a piece of macro code that uses the find function to search through a word document to locate a particular instance of a font with certain formatting.
The code works fine on documents without textboxes but on any document that contains textboxes and multiple stories the find function is reporting that .Found = True but it is then not highlighting anything that it has found. I have posted the find code I am using below. Anyone got any ideas??
For Each oStory In ActiveDocument.StoryRanges
With ActiveDocument.Content.Find
.ClearFormatting
.Font.Name = strFontToFind
.Font.Size = strFontSizeToFind
.Font.Bold = FontBoldIndicator
.Font.Italic = FontItalicIndicator
With .Replacement
.ClearFormatting
.Highlight = True
End With
Search_Font = ActiveDocument.Content.Find.Font.Name
Search_Size = ActiveDocument.Content.Find.Font.Size
MsgBox ("Search Font = " & Search_Font)
MsgBox ("Search Size = " & Search_Size)
'.Text = ""
'.Replacement.Text = ""
'.Forward = True
'.Wrap = wdFindContinue
'.Format = True
'.MatchCase = False
'.MatchWholeWord = False
'.MatchWildcards = False
'.MatchSoundsLike = False
'.MatchAllWordForms = False
'.Highlight = True
.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 that uses the find function to search through a word document to locate a particular instance of a font with certain formatting.
The code works fine on documents without textboxes but on any document that contains textboxes and multiple stories the find function is reporting that .Found = True but it is then not highlighting anything that it has found. I have posted the find code I am using below. Anyone got any ideas??
For Each oStory In ActiveDocument.StoryRanges
With ActiveDocument.Content.Find
.ClearFormatting
.Font.Name = strFontToFind
.Font.Size = strFontSizeToFind
.Font.Bold = FontBoldIndicator
.Font.Italic = FontItalicIndicator
With .Replacement
.ClearFormatting
.Highlight = True
End With
Search_Font = ActiveDocument.Content.Find.Font.Name
Search_Size = ActiveDocument.Content.Find.Font.Size
MsgBox ("Search Font = " & Search_Font)
MsgBox ("Search Size = " & Search_Size)
'.Text = ""
'.Replacement.Text = ""
'.Forward = True
'.Wrap = wdFindContinue
'.Format = True
'.MatchCase = False
'.MatchWholeWord = False
'.MatchWildcards = False
'.MatchSoundsLike = False
'.MatchAllWordForms = False
'.Highlight = True
.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