macro deleting pages

J

Julia

Hi - this macro should find "Invoice=" and then select from the previous page
break to the following page break and delete. It's deleting multiple pages.
Any ideas why? I really appreciate the help:

Sub BillAdd1()
'

With Selection
.WholeStory
.ExtendMode = False
.Collapse
End With

With Selection.Find

.Text = "invoice="
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop

.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False


While .Execute
' Selection.Find.Execute
Selection.HomeKey unit:=wdLine
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
'.Wrap = wdFindAsk

End With
Selection.Find.Execute
Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk


End With
Selection.Find.Execute
Selection.Delete unit:=wdCharacter, Count:=1
Selection.MoveDown unit:=wdLine
Wend

End With

End Sub
 
D

Doug Robbins

Once you find the "Invoice=", delete the range of the built-in bookmark
"\page"

Selection.Bookmarks("\page").Range.Delete

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
J

Julia

Thanks Doug. I don't know enough to know where to place that line of code
you gave me, but I'm trying. thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top