【问题标题】:WORD 2010 Macro for Editing Headers & Footers用于编辑页眉和页脚的 WORD 2010 宏
【发布时间】:2016-12-05 22:52:42
【问题描述】:

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

对各种 VBS 选项的研究显示了几种创建页脚和在宏中进行全局页脚设置更改的方法。但是,如果我只是想在页脚中修改公司名称(例如),我无法在宏子例程中执行此操作。

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

WORD 2010 Macro-VBA 是否排除了简单的 Edit-Footer 功能?

提前致谢

所以,感谢 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
`

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    这是一种您可以通过 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
    

    这里是示例代码的链接,该链接介绍了如何更改文件夹中每个文件的标题。它采用不同的方法,我从未尝试过,但供您参考:http://www.vbaexpress.com/kb/getarticle.php?kb_id=45

    【讨论】:

    • 谢谢!!我已经看到了这种语法,并认为它基本上用“FUBAR”材料[:)] 完全替换了页眉和/或页脚......仍然不允许我在页脚中挑选和选择我的编辑(比如替换前 3 个单词或最后一句话等)。所以每个文件都有一个唯一的页码方案(不是字段编码),所以完全替换不是我设想的解决方法。
    • 谢谢(再次)。您的建议和提供的链接相结合,引导我修复。这是允许我进入页脚和编辑部分的“简单”例程。 Sub Sub_FTR_0() ' ' Sub_FTR_0 宏 ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter For i = 1 To ActiveDocument.Sections.Count '(REM) 添加:FOOTER EDIT Selection.[cmds] If i = ActiveDocument.Sections.Count然后 GoTo Line1 ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter Line1: Next ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End Sub
    • code Sub Sub_FTR_0() ' ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter For i = 1 To ActiveDocument.Sections.Count '(REM) 添加:页脚编辑选择。[cmds] If i = ActiveDocument.Sections.Count Then GoTo Line1 ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter Line1: Next ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End Sub code
    • 很高兴它有帮助。在您的问题中发布您的新代码,以便用户可以看到您的解决方案,如果我的回答有效,您可以单击其左上角的复选标记以“接受”它。 :)
    • 如何设置食物?
    【解决方案2】:

    这适用于文档中的所有页面。

    word.ActiveDocument.Sections(1).Headers(1).Range.Text = "把标题放在这里"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 2015-01-05
      • 2018-08-17
      相关资源
      最近更新 更多