如何使用Word VBA在上一页上读取标题的文本?
首先,我制作一个带有2页的Word Doc。
然后,我添加了一个标题,例如
Current {page}, total {numpages}
{page}
和{numpages}
是字段代码。因此,Currnet 1,总计2
在第一页上显示,而Currnet 2,总计2
在第二页上显示。
我的问题是,在我的情况下,我们如何在上一个页面上读取标题的文本,这应该是Currnet 2,总计2
。
我只能写只
Sub a()
MsgBox ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text
End Sub
写第一页上的文本,即Currnet 1,总计2
。
有帮助吗?谢谢。
Firstly, I make a WORD doc with 2 pages.
Then, I add a header like
Current {page}, total {numpages}
where {page}
and {numpages}
are field codes. So Currnet 1, total 2
is shown on the first page, while Currnet 2, total 2
is shown on the 2nd page.
My question is, how can we read the header's text on last page, in my case, which should be Currnet 2, total 2
.
I can but only write
Sub a()
MsgBox ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text
End Sub
which can only read the text on first page, i.e. Currnet 1, total 2
.
Any help? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可以:
要获取当前部分的最后一页标题,请替换
:
Yes, you can:
To get the last page header for the current Section, replace:
with:
获取有关每个二手标头的报告&页脚,您可能会使用以下内容:
不用担心文本字符串仅适用于每个部分中每个标头/页脚中的第一页。重要的是存在所需的字段。
To get a report on every used Header & footer, you might use something like:
Don't worry that the text string is only for the first page in each Header/Footer in each Section. What matters is that the required fields are present.
你不能。
但是,如果您想获取文档的最后一页的数量,则可以使用
并获取页面数量
You can't.
But, if you want to get the number of the last page of the document you can use
And to get the number of pages