将文档属性字段添加到页脚会删除现有的页码 [英] Adding document property field to footer removes existing page numbering

查看:40
本文介绍了将文档属性字段添加到页脚会删除现有的页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文档中每一页的页脚中标记一个文档变量字段.我已经想出了如何添加字段.但是,这样做时,页脚中已经存在的页码字段将被禁用,只留下文本并且不再充当动态页码.任何帮助将不胜感激.

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 field that already exists in the footer becomes disabled, leaving only the text and no longer acting as a dynamic page number. Any help would be appreciated.

这是我添加字段的代码,但以某种方式禁用了页码.("sectionFooter.Range.Text = sectionFooter.Range.Text + " "" 行是我能找到的唯一方法来让页码仍然显示):

Here is my code that adds the field, but disables the page numbers somehow. (the "sectionFooter.Range.Text = sectionFooter.Range.Text + " "" line is the only way I could find to even get the page number to still show):

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

推荐答案

如果这就是您希望新字段定位的方式,请尝试这样的操作...

If that is how you want the new field positioned, then try something like this ...

Dim docSection As word.Section, sectionFooter As word.HeaderFooter
Dim rng As word.Range
For Each docSection In ActiveDocument.Sections
    For Each sectionFooter In docSection.Footers
        Set rng = sectionFooter.Range
        rng.InsertParagraphAfter
        rng.Collapse wdCollapseEnd
        rng.Font.Size = 8
        rng.Font.Name = "Arial"
        rng.Fields.Add Range:=rng, Type:=wdFieldEmpty, Text:="DOCVARIABLE  ndGeneratedStamp", PreserveFormatting:=False
    Next
Next

这篇关于将文档属性字段添加到页脚会删除现有的页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆