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
---
Message posted from http://www.ExcelForum.com/
Never mind.... it took some playing but I figured out the solution.
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
footer = "From this point to EOF."
Selection.Find.Execute
Found = Selection.Text
If footer <> Found Then End
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
End Su
--
Message posted from http://www.ExcelForum.com
Helmut Weber - 05 Nov 2004 07:28 GMT
Hi,
if .execute then
would be sufficient.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Helmut Weber - 06 Nov 2004 12:37 GMT
Hi,
still a bit messy ;-)
Sub Test()
Dim rDoc As Range
Set rDoc = ActiveDocument.Range
ResetSearch
With rDoc.Find
.Text = "design"
If .Execute Then
rDoc.End = ActiveDocument.Range.End
rDoc.Delete
End If
End With
ResetSearch
End Sub
' ---
Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/