Word VSTO get a range for each page of a document

F

fedebona

I'm experiencing some trouble to solve this issue:
I want to loop through a Word document and get for each page a range that
covers exactily the entire page.
I know that exists a goto method that lets to simply navigate through pages,
but the range that returns is an empty range that covers only the beginning
of a page. Here's some sample code in C#:

Word.Range wholeDocRange = activeDoc.Range(ref missing, ref missing);
int maxPage =
(int)wholeDocRange.get_Information(Word.WdInformation.wdNumberOfPagesInDocument);

// GoTo to navigate the pages
for (int page = 1; page <= maxPage; page++) {
object what = Word.WdGoToItem.wdGoToPage;
object which = Word.WdGoToDirection.wdGoToAbsolute;
object count = page;
Word.Range pageRange = wholeDocRange.GoTo(ref what, ref
which,
ref count, ref missing);

...............

}
}

In this sample pageRange doesn't represent the entire page, but only the
beginning.
 
D

Doug Robbins - Word MVP

Can't help you with the C# coding, but the approach that I would take would
be to go to the beginning of the documnet, set a Range object to the range
of the builtin bookmark "\page", do what you want with your Range object,
then delete the range of the bookmark "\page" which will delete the first
page of the documnet so that the second page will now be the first page and
keep on repeating the process, using a counter integrates until it gets to
what was the original number of pages in the document to control when the
process should stop.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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