【问题标题】:MS Word VBA to link previous footer for multiple sections and pagesMS Word VBA 链接多个部分和页面的上一个页脚
【发布时间】:2021-09-07 04:52:10
【问题描述】:

我有一个 MS Word (2010),我的文档有数百个部分,而我实际上只需要有限数量的具有相同页脚的部分。

我想要一个可以循环浏览选定页面并将所有页脚更改为链接到上一个的宏。

我录制了一个宏,它将为一个部分执行此操作,我该如何更改代码,以便如果我选择了一堆页面(例如 25 个),它将压缩所有页面?

Sub LinkToPrev_Foot()
'
' LinkToPrev_Foot Macro
'
'
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
        LinkToPrevious
   ' ActiveWindow.ActivePane.View.NextHeaderFooter
End Sub

【问题讨论】:

  • 为什么有这么多节?

标签: vba ms-word footer


【解决方案1】:

您需要遍历文档的各个部分。下面的代码假定您只使用三种类型的页脚中的一种。

Public Sub LinkToPrev_Foot()
    Dim ftr As HeaderFooter
    Dim sec As Section

    For Each sec In ActiveDocument.Sections
        'can't link the first section to a previous one
        If sec.Index > 1 Then
            'if document has other types of footer you'll need to loop through them
            sec.Footers(wdHeaderFooterPrimary).LinkToPrevious = True
        End If
    Next sec
End Sub

【讨论】:

  • 我不想遍历文档的所有部分。我只想循环浏览所选页面的各个部分。因此,如果我在 100 页的文档中有 50 个部分,并且我只选择了第 10-35 页,我只想循环浏览这几个部分。
  • @user918967 - 然后只需将ActiveDocument.Sections 更改为Selection.Sections
猜你喜欢
  • 2012-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
  • 2010-11-18
  • 1970-01-01
  • 2012-09-30
相关资源
最近更新 更多