Couldn't find the answer I was looking for.
I want to get the current page number String including its format.
For example: Some sections may have chapter identifier (1-1), some are in Roman style, etc..
My hope was to get the selection of the specific footer, then loop through the fields and get the Page field data (Output is the String I want).
So far as I can see, there is no option to loop through the footers of a given section, just get the general template and try working with it.
I'm aware of wdActiveEndAdjustedPageNumber
from Selection.Range.Information
, but it just gives me partial information.
Am I wrong? Is there a way to work with a specific footer I choose?
If not, can you guide me how to get the following data:
- Closest chapter number value
- Getting the page number value of a special format such as Roman, Alphabetical font (Meaning applying the page format on the
wdActiveEndAdjustedPageNumber
)
Thanks.
Edit for clarification:
In my word template, the Heading 1 style creates the following header: Chapter 1, followed by Chapter 2 and so on.
In page number format, there is an option to include the current Chapter value to the page number.
For example: Assuming the following setup
will result with these pages in the{ PAGE }
field: 1-1, 1-2, 1-3, ... My goal is to somehow get this entire "value" for a specific page footer.
Here is a code snippet which won't work properly:Sub getPageFieldInFooter() ' get current section number Dim sectionNum As Integer sectionNum = Selection.Range.Information(wdActiveEndSectionNumber) 'select first page footer, loop through its fields and find Page field ActiveDocument.Sections(sectionNum).Footers(wdHeaderFooterPrimary).Range.Select Dim f As Field For Each f In Selection.Fields If f.Type = wdFieldPage Then ' do something with the page data MsgBox f.Data End If Next f End Sub
The output of such a method is '1-1'
The reason it won't work is because it can retrieve the first page only (or the second usingwdHeaderFooterEvenPages
).Same goes for Roman number format, or any other from that list.
For the following page number settings, I wish to get the "value" in a specific footer.
The code above will return the values for first or second page, and that's it.
Is there a way to access any footer in the document and perform my code example?
If not, how can I get the page number "value" for any footer I choose?
Hope this is clearer.