Good question in this question, you can view the entire document using the result of Selection.Find.Found .
What you do is start the search, and if you find the result, go into the loop only when the result of Selection.Find.Found is true. Once you get through this, you're done. The following code should do the trick for you.
Sub SearchFN() Dim iCount As Integer 'Always start at the top of the document Selection.HomeKey Unit:=wdStory 'find a footnote to kick it off With Selection.Find .ClearFormatting .Text = "&&FB:*&&FE" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False .MatchControl = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchFuzzy = False .MatchWildcards = True .Execute End With 'If we find one then we can set off a loop to keep checking 'I always put a counter in to avoid endless loops for one reason or another Do While Selection.Find.Found = True And iCount < 1000 iCount = iCount + 1 'Jump back to the start of the document. Since you remove the 'footnote place holder this won't pick up old results Selection.HomeKey Unit:=wdStory Selection.Find.Execute 'On the last loop you'll not find a result so check here If Selection.Find.Found Then ''================================== '' Do your footnote magic here ''================================== 'Reset the find parameters With Selection.Find .ClearFormatting .Text = "&&FB:*&&FE" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False .MatchControl = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchFuzzy = False .MatchWildcards = True End With End If Loop End Sub
CuberChase
source share