- Joined
- Oct 19, 2017
- Messages
- 4
- Reaction score
- 0
Need VBA Macro to Loop through pages and print counter in footer of each page.
The basic need is to insert a visible sequential number in the footer of each page that equates to the page's position in the entire document in a multi-section document with section based page numbering.
I have tried to achieve this through fieldcodes to no avail. A fieldcode solution would be preferable.
However, a macro that could be run before saving the document as a final document would work too.
I have a programming background. However, I have not done any significant coding since Microsoft introduced Document models. I am familiar with object modeling but not the specific implementation in Word. As a very simple macro approach, if i knew the proper object model variables and functions to use, I would:
Start.
Create variable "counter".
Set counter to 1.
Go to first page.
Print counter in footer.
Loop
Increment counter.
Go to to next page.
Print counter in footer.
If last page then endloop else loop.
Stop.
I would also need to know how to specifically position the inserted counter into the footer. It will have prefix that will be document specific. With the fieldcode solution I was trying: <prefix>.<fieldcode>. This works fine in the core document (leaves an increment problem) but not in the footer. I was hoping the footer would handle the incrementing but it doesn't seem to be implemented in a manner to support this.
Simplicity is better than elegance in this case, since I might not be able to fully follow the elegant solution and I may want to tweak minor details. Both would be OK.
Thanks from the old guy.
The basic need is to insert a visible sequential number in the footer of each page that equates to the page's position in the entire document in a multi-section document with section based page numbering.
I have tried to achieve this through fieldcodes to no avail. A fieldcode solution would be preferable.
However, a macro that could be run before saving the document as a final document would work too.
I have a programming background. However, I have not done any significant coding since Microsoft introduced Document models. I am familiar with object modeling but not the specific implementation in Word. As a very simple macro approach, if i knew the proper object model variables and functions to use, I would:
Start.
Create variable "counter".
Set counter to 1.
Go to first page.
Print counter in footer.
Loop
Increment counter.
Go to to next page.
Print counter in footer.
If last page then endloop else loop.
Stop.
I would also need to know how to specifically position the inserted counter into the footer. It will have prefix that will be document specific. With the fieldcode solution I was trying: <prefix>.<fieldcode>. This works fine in the core document (leaves an increment problem) but not in the footer. I was hoping the footer would handle the incrementing but it doesn't seem to be implemented in a manner to support this.
Simplicity is better than elegance in this case, since I might not be able to fully follow the elegant solution and I may want to tweak minor details. Both would be OK.
Thanks from the old guy.