help the number of a word document

V

Victor

hi guys
i have a part of code to find out how many pages in a word document.
actually most of part of the code is from the msdn.
but it didnt work properly. i already load the doc before i excuted the
code.
can anyone tell me why?

private ApplicationClass wd;

wd.ActiveDocument.Repaginate ();
int nStartPg;
int nEndpg;
int nSecpages;
int NumSections;
int total = 0;
NumSections = wd.ActiveDocument.Sections.Count ;

nStartPg = 1;
foreach(Microsoft.Office.Interop.Word.Section oSec in
wd.ActiveDocument.Sections)
{
nEndpg =
(int)oSec.Range.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdActiveEndPageNumber)
-1;
//if (NumSections == oSec.Index)
{
nEndpg ++;
}
nSecpages = nEndpg - nStartPg + 1;
nStartPg = nEndpg + 1;
total += nSecpages;

}


cheers
 
C

Cindy M -WordMVP-

Hi Victor,
i have a part of code to find out how many pages in a word document.
actually most of part of the code is from the msdn.
but it didnt work properly. i already load the doc before i excuted the
code.
Please describe HOW it did not work properly.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
V

victor

My code will get the number of pages for all word docs as 2 or 3. but in fact
some of the word docs is 32 pages long.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?dmljdG9y?=,
My code will get the number of pages for all word docs as 2 or 3. but in fact
some of the word docs is 32 pages long.
Have you tried using the argument wdNumberOfPagesInDocument (for the entire
document)?

I don't know why you'd be getting such a small number, I'd expect a larger one.
You ARE checking the variable total, and not another one? If that's the case,
then I'd say your code is resetting in each loop, although I can't see where
it's happening. If I were in your position, I'd probably set a break-point and
step through the loop, watching the variable's values to see where the mistake
is.

FWIW wdActiveEndPageNumber doesn't give you the number of pages in a section,
which appears to be how you're trying to use it; it gives you the page number
from the beginning of the document. ActiveEndAdjustedPageNumber might be more
appropriate for the approach you're trying to use, if you've reset the page
numbering for each section.

But normally I'd use wdNumberOfPagesInDocument.

private ApplicationClass wd;

wd.ActiveDocument.Repaginate ();
int nStartPg;
int nEndpg;
int nSecpages;
int NumSections;
int total = 0;
NumSections = wd.ActiveDocument.Sections.Count ;

nStartPg = 1;
foreach(Microsoft.Office.Interop.Word.Section oSec in
wd.ActiveDocument.Sections)
{
nEndpg =
(int)oSec.Range.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdAc
tiveEndPageNumber)
-1;
//if (NumSections == oSec.Index)
{
nEndpg ++;
}
nSecpages = nEndpg - nStartPg + 1;
nStartPg = nEndpg + 1;
total += nSecpages;
}

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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