Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting pages in MS Word 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

I'm trying to return the # of pages in a word document. This is what I have so far:
=============================

Sub CountPages()
Dim i As Integer
i = ActiveDocument.Sections(0).Headers(wdHeaderFooterPrimary).PageNumbers.Count
MsgBox i
End Sub
==============================

It keeps returning 0. Does anyone know why, or how to get this number?

Thanks,

Ron

Ron Repp
 
Hi Ron,

Try:
Code:
Sub CountPages()
MsgBox ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
End Sub

Cheers
 
Macropod:

Thanks. That was exactly what I was looking for.

Ron

Ron Repp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top