I have a document with a frame that contains a few lines with FormFields and Fields. One of those lines is “page X of Y”. The primary header of the doc also contains a frame with a line “page X of Y”. In both cases Y is the NumPages field. When there are more than 1 pages in the doc, the Y on all pages is updated, EXCEPT on page 1. See attached file, which is very much stripped down. (If you wonder about some other fields, these are IF fields, presenting text in Dutch or English, depending on the value of CustomDocumentProperty “Taal” (= Dutch for “Language”).)
Whatever I do, in Word itself or through VBA code, I cannot get this field on page 1 to update, unless this field, and only this field(!), is selected and then F9 is pressed or Selection.Fields(1).Update is executed. What am I doing wrong? Can anyone shed some light at this?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
NumPages doesn’t update (WinXP/Office2003 NL)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » NumPages doesn’t update (WinXP/Office2003 NL)
- This topic has 14 replies, 4 voices, and was last updated 19 years, 6 months ago.
AuthorTopicWSJanB
AskWoody LoungerSeptember 6, 2005 at 10:36 am #423785Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerSeptember 6, 2005 at 10:57 am #971105The NUMPAGES field on page 2 and subsequent pages is in a frame in the page header. All fields in the page header are automatically updated when you print or print preview the document.
The NUMPAGES field on page 1 is in a frame in the body. Not all fields in such a frame are updated automatically. Unfortunately, you cannot move this frame “as is” to the header, since it contains form fields.
One solution is to hijack the print commands, and to update all fields in all storyranges – see WD2000: How to Automatically Update Fields.
Another one is to create a userform to collect information, and use this to place information into the frame on page 1, instead of using form fields. You can then move the frame into the page header. -
WSJanB
AskWoody LoungerSeptember 6, 2005 at 11:43 am #971119Hans, thanks for the suggestions. I tried the code in the article you pointed to, but that also doesn’t work. I kinda implied that in my first post but obviously I wasn’t clear enough. Sorry. So let me expand a little. Just for testing I wrote a little Sub that iterates through all fields of the frame and only tries to update the NumPages field:
Sub UpdateFields
Dim fld As Field
For Each fld in ActiveDocument.Frames(1).Range.Fields
If fld.Type = wdFieldNumPages Then
fld.Update
End If
Next fld
End SubExecuting this code does not update the NumPages field. But singlestepping through the code does! I just don’t understand why…
As for your suggestion to create a userform: I’m not allowed to do that. The document is based on a mandatory company “housestyle” template that we have to use “as is”. -
WSHansV
AskWoody LoungerSeptember 6, 2005 at 12:04 pm #971121Sorry, I hadn’t tested the code in your document. I see now that it doesn’t work.
Try the following:
Select the NUMPAGES field in the header on page 2.
Select Insert | Bookmark, and specify a (unique) name for the bookmark, e.g. NumPag.
Close the header, and go to the frame on page 1.
Delete the NUMPAGES field, and change it to a field referring to the NumPag bookmark you just created.
The code still won’t update it, but printing/print previewing should update it. -
WSJanB
AskWoody LoungerSeptember 6, 2005 at 12:59 pm #971136OK, that works for this document. And adding pages leads to updated and correct values of “NumPages” on page 1. Deleting pages also works OK, unless there’s only 1 page left. In that case after updating or with printpreview it says 1 of 2….
So, unless somebody has another brainwave, I’m stuck. -
WSHansV
AskWoody Lounger -
WSPhil Rabichow
AskWoody LoungerSeptember 6, 2005 at 10:19 pm #971280Hi Jan:
I’m not sure why it won’t update correctly after using Print Preview. It does for me using Print Preview (Word 2003). However, I tried using a SET & REF field in place of the Numpages field & it seems to work. See if this helps.Edited to add: Some more checking on a sample document I made. It seems that fields are updating one at a time. i.e. I can put 3 lines on the first page that say
{page} of {numpages}
{page} of {numpages}
{page} of {numpages}select all & then update fields. I have to update three times, with each line updating after pressing F9. Ah ha!! See Microsoft Knowledge Base Article 835227
Cheers, -
macropod
AskWoody_MVPSeptember 7, 2005 at 2:23 am #971304Hi Jan,
Try the following code. I think you’ll find it works!
Cheers
Sub UpdateNumPages()
Dim oRange As Word.Range
Dim oFld As Field
For Each oRange In ActiveDocument.StoryRanges
Do
For Each oFld In oRange.Fields
If oFld.Type = wdFieldNumPages Then oFld.Update
Next
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next
End SubCheers,
Paul Edstein
[Fmr MS MVP - Word] -
WSJanB
AskWoody Lounger -
WSJanB
AskWoody Lounger -
WSJanB
AskWoody LoungerSeptember 7, 2005 at 12:18 pm #971398When you tried, did your code work with the document protection (for formfields) turned on? If I try that, the field isn’t updated. If I turn protection off manually, then your code works. So I put calls to my standard ProtOff and ProtOn sub’s (see below) at the start and end of your code, but then the field wasn’t updated…
Public Sub ProtOff(Optional blnNull As Boolean)
‘Optional argument prevents that Sub is visible in Tools | Macro | Macro list
If Documents.Count < 1 Then Exit Sub
If ActiveDocument.Protection.Type wdNoProtection Then
ActiveDocument.Unprotect Password:=””
End If
End SubPublic Sub ProtOn(Optional blnNull As Boolean)
‘Optional argument prevents that Sub is visible in Tools | Macro | Macro list
If Documents.Count < 1 Then Exit Sub
If ActiveDocument.Protection.Type = wdNoProtection Then
ActiveDocument.Protect Password:="“, NoReset:=True, Type:=wdAllowOnlyFormFields
End If
End Sub -
WSHansV
AskWoody Lounger -
WSJanB
AskWoody Lounger -
macropod
AskWoody_MVPSeptember 7, 2005 at 10:28 pm #971540Hi Jan,
I ran the code on your protected document and it worked fine.
When I ran it with your unprotect/protect code, I got an error on the lines:
If ActiveDocument.Protection.Type wdNoProtection Then
which should be:
If ActiveDocument.ProtectionType wdNoProtection Then
When I correct that, the code still works. Copy with code attached.Cheers
Cheers,
Paul Edstein
[Fmr MS MVP - Word] -
WSJanB
AskWoody LoungerSeptember 8, 2005 at 10:08 am #971620
Sometimes I’m not on my own work-PC when I come into the Lounge and then I cannot upload. So I typed it in and made a typo; in reality I use the same syntax as you did.
In the meantime, I discovered some other strange behaviour regarding my global code-only-template, so I’ll investigate the possibillity of corruption.
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Ubuntu 25.04 (Plucky Puffin) Beta released
by
Alex5723
1 hour, 22 minutes ago -
How to install App Store apps on an external SSD
by
Alex5723
2 hours, 16 minutes ago -
Where is Windows going?
by
Susan Bradley
3 hours, 34 minutes ago -
Does anyone know how can we convert OST to Office 365? (Awaiting moderation)
by
Sanchit Tandon
6 hours ago -
Installing Feature Update Windows 11 24H2
by
geekdom
19 hours, 45 minutes ago -
Windows 11 Insider Preview build 27823 released to Canary
by
joep517
20 hours, 9 minutes ago -
Windows 11 Hotpatch
by
Hackmuss
3 hours, 26 minutes ago -
System Guard service error still won’t be fixed
by
Susan Bradley
20 hours, 48 minutes ago -
Operation ForumTroll: APT attack with Google Chrome zero-day exploit chain
by
Alex5723
14 hours, 59 minutes ago -
Troy Hunt of HaveIBeenPwned Phished
by
Lars220
12 hours ago -
Microsoft Windows security auditing Code 5061
by
mpw
1 day, 9 hours ago -
Can’t display images in incoming Outlook 365 emails
by
WScopwriter
16 hours, 56 minutes ago -
Windows 11 Insider Preview Build 26200.5510 early builds of 25H2
by
Alex5723
18 hours, 24 minutes ago -
0Patch : Micropatches released for SCF File NTLM Hash Disclosure Vulnerability
by
Alex5723
17 hours, 54 minutes ago -
Select multiple emails and they all open up!
by
CeeJay
2 days, 10 hours ago -
How to remove an update preview
by
Gunny
13 hours, 18 minutes ago -
Third party add ins reminder
by
Susan Bradley
8 hours, 53 minutes ago -
OTF, which backs Tor, Let’s Encrypt and more, sues to save its funding
by
Nibbled To Death By Ducks
2 days, 4 hours ago -
Updating Windows 10 to Windows 11: 23H2 or 24H2?
by
Still Anonymous
2 days, 14 hours ago -
How can I update “Explorer Patcher”
by
WSplanckster
2 days, 16 hours ago -
Check out the home page for Signal
by
CAS
2 days, 14 hours ago -
Windows 11 and Trial version of MS Office
by
Tex265
2 days, 13 hours ago -
Windows 11 Insider Preview build 26120.3585 (24H2) released to BETA
by
joep517
2 days, 21 hours ago -
Windows 11 Insider Preview build 26200.5510 released to DEV
by
joep517
2 days, 21 hours ago -
Windows 11 Insider Preview Build 26100.3624 (24H2) released to Release Preview
by
joep517
2 days, 21 hours ago -
Limits on User Names
by
CWBillow
2 days, 18 hours ago -
MS-DEFCON 4: Mixed bag for March
by
Susan Bradley
17 hours, 59 minutes ago -
Non Apple Keyboards
by
pmcjr6142
19 hours, 15 minutes ago -
How to delete your 23andMe data – The Verge
by
AJNorth
2 days, 15 hours ago -
7 common myths about Windows 11 (Microsoft AD)
by
EyesOnWindows
2 days, 13 hours ago
Recent blog posts
- Where is Windows going?
- System Guard service error still won’t be fixed
- Third party add ins reminder
- MS-DEFCON 4: Mixed bag for March
- Classic and Extended Control Panel — no need to say goodbye
- Things you can do in 2025 that you couldn’t do in 2024
- Revisiting Windows 11’s File Explorer
- Planning ahead for migration
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.