WORD 2010用于编辑页眉和页脚的宏

Dan*_*Dan 7 vba ms-word

我只有基本的VBA体验,而我以前的宏部署主要是使用WORD 2003.录制宏用于获取GoToFooter(或编辑页脚)菜单命令并允许后续编辑.在WORD 2010中,此(以及许多其他)命令不会"记录"到宏(但在录制模式下,我确实进入了编辑页脚功能).

对各种VBS选项的研究显示了几种创建页脚并在宏中进行全局页脚设置更改的方法.但是,如果我只想在页脚中修改公司名称(例如),我在Macro子例程中找不到这样做的方法.

这个子程序是我从主宏调用的一个程序,它逐步遍历文件夹(和子文件夹)中的每个文件.我有主要的宏功能.

WORD 2010 Macro-VBA是否排除了简单的编辑页脚功能?

提前致谢

所以,多亏了Issun,这是我的解决方案:

`
Sub Sub_FTR_0()
'
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

For i = 1 To ActiveDocument.Sections.Count
 'REM: INSERT Code from RECORD MACRO recorded when editing one Footer correctly
    Selection. [[xxx]], etc.

If i = ActiveDocument.Sections.Count Then GoTo Line1

    ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter

Line1:
Next

    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

End Sub
`
Run Code Online (Sandbox Code Playgroud)

aev*_*nko 10

这是一种可以通过VBA访问页眉/页脚的方法.正如您所看到的,这是一个相当复杂的语法,可以让它变得如此简单:p

Sub EditHeadersAndFooters()

Dim i As Long

For i = 1 To ActiveDocument.Sections.Count
    With ActiveDocument.Sections(i)
        .Headers(wdHeaderFooterPrimary).Range.Text = "Foo"
        .Footers(wdHeaderFooterPrimary).Range.Text = "Bar"
    End With
Next

End Sub
Run Code Online (Sandbox Code Playgroud)

以下是有关如何更改文件夹中每个文件中的标头的示例代码的链接.它需要一种不同的方法,我从未尝试过,但供您参考:http://www.vbaexpress.com/kb/getarticle.php?kb_id = 45