Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2022, 01:08 PM
nyconfidential nyconfidential is offline Updating page number in table cells in footer in each page Windows 10 Updating page number in table cells in footer in each page Office 2019
Novice
Updating page number in table cells in footer in each page
 
Join Date: Nov 2021
Posts: 4
nyconfidential is on a distinguished road
Default Updating page number in table cells in footer in each page

Hi all - I have several documents that I need to merge together. The merging works fine, but I need to update the page number in each page footer after I am done (the page number and the total page count is stored in 2 table cells in the footer, see attached image - if the document has ten pages and you are on the third page, the first cell will read "3", the second will read "10", etc).

Now, something like the code below works if I put in a loop, but I only if I create a section break on each page (also I have to de-link the footers which is pain).




Code:
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).range.Tables(1).Cell(1, 1).Range = "3"

ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).range.Tables(1).Cell(1, 2).Range = "10"



ActiveDocument.Sections(2).Footers(wdHeaderFooterPrimary).range.Tables(1).Cell(1, 1).Range = "4"

ActiveDocument.Sections(2).Footers(wdHeaderFooterPrimary).range.Tables(1).Cell(1, 2).Range = "10"
I'm sure there's a better way to do this, anyone have any suggestions? (Note, I have to keep the table cells, those are not allowed to change)
Attached Images
File Type: png word page.PNG (564 Bytes, 10 views)
Reply With Quote
  #2  
Old 08-13-2022, 03:37 PM
macropod's Avatar
macropod macropod is offline Updating page number in table cells in footer in each page Windows 10 Updating page number in table cells in footer in each page Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Ordinarily, one would have the same footer on each page. Consequently, changing the number on one page would cause them all to display that number. Assuming your document doesn't have Section breaks between the pages with the footers unlinked (which - as you observe - is a 'pain' to do), all you need do is insert a PAGE field in the first cell and a NUMPAGES field in the second. No code required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
footers, page numbers, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating page number in table cells in footer in each page Page number shows up as { PAGE } instead of number and question about area allowed for footer dw85745 Word 3 01-16-2022 03:19 PM
Table of content to include a page number comprising Section and page number Allen001 Word 2 11-25-2019 05:38 AM
Don't want page number or date in footer on first page, do want graphic in header. dianahbr Word 2 02-23-2018 09:25 AM
Updating page number in table cells in footer in each page Table adding cells to previous page with room still on current page. gedet Word 1 01-03-2018 10:35 AM
Updating page number in table cells in footer in each page Total Page number incorrect in the first page footer mmathisekar Word 11 06-16-2016 06:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft