Selection.Information

B

Brad

Hi,

I am using the following to get the number of pages there
are in a Word document (from within Excel). I can also use
it directly in Word without the "appWrd ".

Dim EndPage as Integer
EndPage = appWrd.Selection.Information
(wdNumberOfPagesInDocument)

This works sometimes, but the other times I get the error
message "Run Time Error 91 Object Variable or With Block
Variable not Set".

Is there something additional I need to do so I do not get
this error? I do not understand why it works sometimes but
not all the times.

THANKS!
 
G

Greg

Brad,

Maybe a variation of:

Dim EndPage As Long
EndPage = ActiveDocument.ComputeStatistics(wdStatisticPages)
would work better.
 
Top