Adding document property field to footer removes existing page numbering

后端 未结 3 385
情书的邮戳
情书的邮戳 2021-01-28 06:54

I am tying to stamp a document variable field in the footer of every page in a document. I have figured out how to add the field. However, in doing so, the page numbering fiel

3条回答
  •  盖世英雄少女心
    2021-01-28 07:27

    Based on my test, we can just remove the commented code too.

    Note If we use this way, we need to set the page-number first then run the Macro.

    Dim docSection As Word.Section, sectionFooter As Word.HeaderFooter 
    For Each docSection In ActiveDocument.Sections
        For Each sectionFooter In docSection.Footers
                'sectionFooter.Range.Collapse wdCollapseEnd
                'sectionFooter.Range.Text = sectionFooter.Range.Text + " "
                sectionFooter.Range.Collapse wdCollapseEnd
                Dim newPP As Paragraph
                Set newPP = sectionFooter.Range.Paragraphs.Add()
    
                newPP.Range.Font.Size = 8
                newPP.Range.Font.Name = "Arial"
                ActiveDocument.Fields.Add Range:=newPP.Range, Type:=wdFieldEmpty, Text:="DOCVARIABLE  ndGeneratedStamp", preserveformatting:=False
    
        Next
    Next
    

提交回复
热议问题