VBA In MS Word to return the page number

Posted on 2003-03-28
Medium Priority
Last Modified: 2008-02-01

I have been sweating over this for the last 2 days, and if someone could help, I would be oh so grateful.

My problem seems really quite simple.  All I want to do is return the current page number on an MS Word document programmatically.

I have a large 400 page document and all I want to do is run a small procedure to move between headings and return the page number:

   *Some code to return the current page number*
      Selection.GoTo What:=wdGoToHeading, which:=wdGoToNext
   *Some code to return this page number*  

This should in theory give two integers which I use to print the pages between the two headings.

If anyone could help, it really would be great.

Thank you so much.
Question by:IainInLondon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 44

Accepted Solution

bruintje earned 120 total points
ID: 8224978
Hello IanInLondon,

Check out Selection.Information in the VBA help file.


Returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document. Any manual adjustments to page numbering are disregarded


Returns the number of the page that contains the active end of the specified selection or range. If you set a starting page number or make other manual adjustments, returns the adjusted page number.

and you could do something like

CurrentPage = Selection.Information(wdActiveEndPageNumber)
LastPage = Selection.Information(wdNumberOfPagesInDocument)
MsgBox "The selection is on page " & CurrentPage & " of page " & LastPage


Author Comment

ID: 8225052
Hey Bruintje


This is the line was looking for.

You are absoulute gem!  

Thank you so much.


Author Comment

ID: 8225073
I just wish there something more I could do to thank you....!

What a....emm...person! (I can't tell if you are a guy or girl! sorry..)
LVL 44

Expert Comment

ID: 8225096
:) we're here always to help ... so thank you is enough

it's good enough to see people get on

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question