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, 7 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
-
April 2025 Office non-Security updates
by
PKCano
5 hours, 14 minutes ago -
Microsoft wants to hear from you
by
Will Fastie
6 hours, 25 minutes ago -
Windows 11 Insider Preview Build 22635.5160 (23H2) released to BETA
by
joep517
8 hours, 46 minutes ago -
Europe Seeks Alternatives to U.S. Cloud Providers
by
Alex5723
14 hours, 17 minutes ago -
Test post
by
Susan Bradley
16 hours, 31 minutes ago -
Used Systems to delete Temp files Gone WRONG what does this mean?
by
Deo
18 hours, 12 minutes ago -
SSD shuts down on its own
by
CWBillow
9 hours, 36 minutes ago -
OneDrive File Sharing Changes
by
David Clark
1 day, 2 hours ago -
OneDrive File Sharing Changes
by
David Clark
1 day, 4 hours ago -
Win 10 Pro 22H2 to Win 11 Pro 23H2 Conversion Guide
by
doneager
4 hours, 23 minutes ago -
Today is world backup day
by
Alex5723
19 hours, 56 minutes ago -
Windows .exe on Mint
by
Slowpoke47
1 day, 5 hours ago -
Reviewing your licensing options
by
Susan Bradley
15 hours, 37 minutes ago -
Apple has been analyzing your photos since September 2024
by
B. Livingston
1 hour, 9 minutes ago -
What Windows 11 24H2 offers beyond bugs
by
Lance Whitney
8 hours, 57 minutes ago -
Making sense of Settings in Windows 11
by
Simon Bisson
16 hours, 10 minutes ago -
Windows 11 pro fails to log in after upgrading Win 10 pro to Win 11 pro 24h2
by
ben_sitaud
1 day, 2 hours ago -
23H2 / 24H2 / Local v. Microsoft Account.
by
CWBillow
23 hours, 55 minutes ago -
YouTube Ad Blocker Blocker
by
bbearren
1 day ago -
Obscure historical facts about Windows
by
Cybertooth
1 day, 1 hour ago -
Microsoft Backup
by
Linda2019
17 hours, 29 minutes ago -
What is the best notepad++ version for W7?
by
Picky
1 day ago -
What are right steps to move MS 365 Office+OneDrive files from PC to iMac?
by
glnz
2 days, 10 hours ago -
How to move existing MS 365 Office with OneDrive files from PC to new iMac
by
glnz
2 days, 10 hours ago -
How to move MS 365 files (some on OneDrive) from PC to iMac
by
glnz
3 days, 5 hours ago -
Microsoft adding Quick Machine Recovery to Windows 11
by
Alex5723
3 days, 5 hours ago -
Microsoft vs Passwords
by
Alex5723
13 hours, 22 minutes ago -
Windows 11 Insider Preview build 26200.5516 released to DEV
by
joep517
3 days, 9 hours ago -
Windows 11 Insider Preview build 26120.3653 (24H2) released to BETA
by
joep517
3 days, 9 hours ago -
Two March KB5053606 updates?
by
Adam
3 days, 3 hours ago
Recent blog posts
Key Links
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
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.