Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

VBA In MS Word to return the page number

Hello.

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.
Iain
0
IainInLondon
Asked:
IainInLondon
  • 2
  • 2
1 Solution
 
bruintjeCommented:
Hello IanInLondon,

Check out Selection.Information in the VBA help file.

Selection.Information(wdActiveEndPageNumber)

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

Selection.Information(wdActiveEndAdjustedPageNumber)

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

HAGD:O)Bruintje
0
 
IainInLondonAuthor Commented:
Hey Bruintje

**Selection.Information(wdActiveEndPageNumber)**

This is the line was looking for.

You are absoulute gem!  

Thank you so much.

Iain
0
 
IainInLondonAuthor Commented:
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..)
Thanks
0
 
bruintjeCommented:
:) we're here always to help ... so thank you is enough

it's good enough to see people get on
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now