积极答复者
如何用vba修改word页眉中的文本框内容?

问题
-
在网上找的,有人给了这么个东西,说能解决
Sub TexBox()
Dim iShape As Shape
For Each iShape In ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes
If iShape.Type = msoTextBox Then
iShape.TextFrame.TextRange = "这是页眉的文本框!"
'把这里的文本换成存储 userform.textbox 数据的变量即可
Exit Sub
End If
Next
End Sub因为以前程序是其他语言(powerbuilder)编程,我试着改为
ole_word.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.TextFrame.TextRange = "这是页眉的文本框!" ,运行报错
请问wdHeaderFooterPrimary常量的具体数值是什么?还有这语句是不是能修改页眉文本框呢?
答案
-
Hi,
你看看这个文档: http://msdn.microsoft.com/en-us/library/ms178795.aspx
在VB。net中是可以这样引用的Word.WdHeaderFooterIndex.wdHeaderFooterPrimary
(这里是VB。net论坛, 一般不讨论VBA的问题)
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年7月11日 8:56
-
对了, 它的值是1, wdHeaderFooterFirstPage的值是2,wdHeaderFooterEvenPages的值是3.
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年7月11日 8:56
全部回复
-
Hi,
你看看这个文档: http://msdn.microsoft.com/en-us/library/ms178795.aspx
在VB。net中是可以这样引用的Word.WdHeaderFooterIndex.wdHeaderFooterPrimary
(这里是VB。net论坛, 一般不讨论VBA的问题)
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年7月11日 8:56
-
对了, 它的值是1, wdHeaderFooterFirstPage的值是2,wdHeaderFooterEvenPages的值是3.
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年7月11日 8:56