How to select entire page?

S

sthomas

I am searching for text, and when found I want to select/cut the entire
page (that the text was found on) into a seperate document. The pages
are not equal length (use Page Breaks).

I have found that I can use selection.find to the text, then move to
the beginning of the page using Selection.GoTo. I can even move to the
beginning of the next page (again using selection.goto) but I can't use
the Extend:=wdExtend with this - so I cannot highlight the page.

Any help would be appreciated :)
 
J

JGM

Hi sthomaS

Try the following

Dim myRange As Range

Set myRange = ActiveDocument.Bookmarks("\Page").Range

'the predefined "\Page" bookmark reprsent the page where the cusor is
located. But it includes the page break as well, if there is one. So either
you use the following line to remove the page break from the range, but if
you are on the last page there won't be one... so you might end up removing
the last paragraph mark....Or you can decide not to use following line of
code and handle the possible page break differently...
myRange.SetRange Start:=myRange.Start, End:=myRange.End - 1

myRange.Select
'or
myRange.Copy
'or
myrange.Delete

etc.

Try not to use the selection object as much as possible because it involves
more code and it often leads to all kinds of conflicts if it is not written
appropriately. The range object is much more robust and also avoids having
to select the actual text.

HTH
Cheers!
 

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