How to retrieve the content of a page

I

Inbar

I am looking for a way to retrieve the text content of a page. I didn't seem
to find an easy way to do this in vba. Any ideas?
 
H

Helmut Weber

Hi,
are you lookong for:
Selection.Bookmarks("\page").Range.Select,
which selects the page the beginning of the selection is on.
But you may have to switch just once to printview beforehand.
And I can't think of a way to get the content of a specific page
without moving the selection to that page. Once it is there,
the following would be an alternative.
dim s as string
s = Selection.Bookmarks("\page").Range.text
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
C

Chuck

In addition to Helmut's suggestion, you can also use a range to navigate to a
specific page, then use the "\page" bookmark to select the content of that
page:

Sub GetPageContents()

Dim rngRange As Range
Dim lngPageNum As Long

lngPageNum = InputBox("What page?")
'you can determine the page number you want in code
'or through a user interaction such as InputBox etc

Set rngRange = ActiveDocument.GoTo _
(What:=wdGoToPage, _
Which:=wdGoToAbsolute, _
Count:=lngPageNum)
'you can set the GoTo params as you like
rngRange.Select
Set rngRange = ActiveDocument.Bookmarks("\Page").Range

'Now you have the contents of the page as a range object,
'you can do what you need to do with the range object

End Sub

Hope this helps...
 

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