• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 54
  • Last Modified:

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
0
Andreas Hermle
Asked:
Andreas Hermle
  • 4
  • 3
1 Solution
 
GrahamSkanRetiredCommented:
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

0
 
Andreas HermleTeam leaderAuthor Commented:
Hi Graham,

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

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

Andreas
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
GrahamSkanRetiredCommented:
HI Andreas,
You're working late
G
0
 
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  ;-)
0
 
GrahamSkanRetiredCommented:
if it were anyone else, I would suspect that Gewürztraminer might be causing a problem.
0
 
Andreas HermleTeam leaderAuthor Commented:
laughing out loud roll on floor :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now