Replace numpages-field with a sectionpages-field in all footers of the active multi-section-document

Dear Experts:

I would like to run a macro with the following requirements. The macro is to run on the active multi-section document.

Replace the {NUMPAGES}-Field in the footer (wdheaderfooterprimary) with a {SECTIONPAGES}-Field

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Andreas. Try this macro
Sub EditFields()
Dim sec As Section
Dim fld As Field

For Each sec In ActiveDocument.Sections
    For Each fld In sec.Footers(wdHeaderFooterPrimary).Range.Fields
        If fld.Type = wdFieldNumPages Then
            fld.Code.Text = Replace(fld.Code.Text, "NUMPAGES", "SECTIONPAGES", vbTextCompare)
        End If
    Next fld
Next sec
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi Graham,

as always from your side concise and working coding. Thank you very much for it.

Regards, Andreas
Andreas HermleTeam leaderAuthor Commented:
Great job. Thanx

CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

HI Andreas,
You're working late
Andreas HermleTeam leaderAuthor Commented:
It is fun to know that the things I will get work the way I want it, so anyime to retrieve the information is opportune ... upps I am not quite sure if this makes sense  ;-)
if it were anyone else, I would suspect that Gewürztraminer might be causing a problem.
Andreas HermleTeam leaderAuthor Commented:
laughing out loud roll on floor :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.