#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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 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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
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! |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |