W
WordCrafter
I used the macro recorder to capture the keystrokes of finding a string.
Once it finds the string, it deletes from the point of the start of the
string to end of the document.
When the string exists, the macro works correctly. When the text does
not exist, the WHOLE document gets deleted. I'm trying to figure out how
to capture the string-not-found condition and cause the routine to exit
without completing the deletion.
Private Sub RemoveFooter()
'
' RemoveFooter Macro
' Macro recorded 11/2/2004 by bs2829
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
..Text = "From this point to EOF"
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
Once it finds the string, it deletes from the point of the start of the
string to end of the document.
When the string exists, the macro works correctly. When the text does
not exist, the WHOLE document gets deleted. I'm trying to figure out how
to capture the string-not-found condition and cause the routine to exit
without completing the deletion.
Private Sub RemoveFooter()
'
' RemoveFooter Macro
' Macro recorded 11/2/2004 by bs2829
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
..Text = "From this point to EOF"
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub