Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2019, 10:53 PM
Fabulist Fabulist is offline Can page fields update automatically? Windows 10 Can page fields update automatically? Office 2016
Advanced Beginner
Can page fields update automatically?
 
Join Date: Sep 2015
Posts: 33
Fabulist is on a distinguished road
Default Can page fields update automatically?

Hello,




I have a macro combination which updates all fields in the document and resizes and reshapes all objects with some of them conditionally.


Two pages before the last there is a { PAGE } field.


Not only I cannot find a way to have this field to be continuously updated, like for example the page fields on the footers are, but I cannot even figure out a way for it to be updated right after all fields are updated and objects reshaped from the macro.


The pages field is always being updated wrong and manual update is required, or to run the macro twice, which is a very lengthy process.


Is there a way to have such fields automatically updated always, or make a page-specific VBA code to only update said field?


Thanks.
Reply With Quote
  #2  
Old 08-21-2019, 01:11 AM
gmayor's Avatar
gmayor gmayor is offline Can page fields update automatically? Windows 10 Can page fields update automatically? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Replace the field with a text content control titled "PageNum" and use the following macro to populate/update it:
Code:
Sub UpDatePageNum()
Dim oCC As ContentControl
    Set oCC = ActiveDocument.SelectContentControlsByTitle("PageNum").Item(1)
    oCC.Range.Text = oCC.Range.Information(wdActiveEndPageNumber)
    Set oCC = Nothing
End Sub
If you have more than one such field in the body of the text then replace each of them with a content control titles PageNum and use the following code to populate/update them all:
Code:
Sub UpDatePageNum()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.Range.ContentControls
        If oCC.TITLE = "PageNum" Then
            oCC.Range.Text = oCC.Range.Information(wdActiveEndPageNumber)
        End If
    Next oCC
    Set oCC = Nothing
End Sub
You may find Insert Content Control Add-In useful
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-21-2019, 11:40 AM
Fabulist Fabulist is offline Can page fields update automatically? Windows 10 Can page fields update automatically? Office 2016
Advanced Beginner
Can page fields update automatically?
 
Join Date: Sep 2015
Posts: 33
Fabulist is on a distinguished road
Default

Sorry for the late reply.


Brilliant, it works great as a manual update after the macro is done.



I also replaced wdActiveEndPageNumber with wdActiveEndAdjustedPageNumber because I have the first page not being counted.


Thank you for this!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can page fields update automatically? Update fields of the same type automatically mqdias Word 3 08-08-2017 03:18 AM
Automatically Update Version jhodgkins Visio 0 11-29-2016 01:45 PM
Can page fields update automatically? Automatically update page numbers when new pages inserted nvidovic Word 2 05-23-2012 10:57 AM
Does Word have an option to update fields AUTOMATICALLY at open??? Jamal NUMAN Word 17 01-27-2012 12:57 AM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:11 PM.


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