G
gaubahn via OfficeKB.com
Hi,
How do i program a macro to run only if certain words are found within a
document. Below is my code (quite unelegant but its the best i can come up
with given my limited VB know-how :]) )
Sub DeleteRemittance()
' Delete Remittance Page
' Macro added on 12/3/2008 by bmsvbs
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "DELETE PAGE"
.Font.Bold = True
.Font.Size = 1
.Font.Name = "Arial"
.MatchCase = True
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.GoTo What:=wdGoToBookmark, Name:="\section"
Selection.Find.ClearFormatting
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.GoTo What:=wdGoToBookmark, Name:="\section"
Selection.Find.ClearFormatting
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
End Sub
The problem with this code is even if the "DELETE PAGE" is not found it still
performs the Selection.TypeBackspace command.
Any ideas for a work around is greatly appreciated.
Thanks and regards,
gau
How do i program a macro to run only if certain words are found within a
document. Below is my code (quite unelegant but its the best i can come up
with given my limited VB know-how :]) )
Sub DeleteRemittance()
' Delete Remittance Page
' Macro added on 12/3/2008 by bmsvbs
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "DELETE PAGE"
.Font.Bold = True
.Font.Size = 1
.Font.Name = "Arial"
.MatchCase = True
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.GoTo What:=wdGoToBookmark, Name:="\section"
Selection.Find.ClearFormatting
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.GoTo What:=wdGoToBookmark, Name:="\section"
Selection.Find.ClearFormatting
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
End Sub
The problem with this code is even if the "DELETE PAGE" is not found it still
performs the Selection.TypeBackspace command.
Any ideas for a work around is greatly appreciated.
Thanks and regards,
gau