在 Word 文档的最后一部分停用 LinkToPrevious

Deactive LinkToPrevious At the Last Section of Word Document

我被要求将 3 个单独的文档放入 1 个 .docx 文件中。第一份文件的页脚应有 X/Y 格式的页码,后面的两份文件不应有页码。我在第一个文档之后立即放置了一个分节符,这样我就可以停用 Link 到上一个选项。但是,我似乎无法使用宏停用文档第二部分的 Link to Previous 选项。我只能用宏停用第一部分或整个文档的 Link 到上一个选项。我知道我可以手动执行此操作,但我不希望用户必须执行此操作。我已经包含了我尝试过的两种方法的代码,但都没有产生预期的结果。

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
     ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
     ActivePane.View.Type = wdOutlineView Then
     ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 
'As I understand it, these lines of code move the cursor to the footer. I got them from recording a macro.

Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.LinkToPrevious 
'This is the line of code generated from recording a macro that deactivated the LinkToPrevious option,
'but when run as part of a macro, it turns off LinkToPrevious for the entire document despite there 
'being a section break on the page prior to where the cursor is when this line of code is executed

ActiveDocument.Sections(2).Footers(wdHeaderFooterPrimary).LinkToPrevious = False 'I also tried this code.
'This turns off LinkToPrevious for the whole document; I only want it turned off for the 
'2nd section of the document

我只想使用宏关闭文档最后一部分的 LinkToPrevious。这能做到吗?

Word 有三种类型的 header 和三种类型的页脚。 ActiveDocument.Sections(2).Footers(wdHeaderFooterPrimary).LinkToPrevious = False 将仅在第二部分 中关闭 LinkToPrevious,但仅针对三种页脚中的一种。如果您不知道文档中使用了哪些,只需遍历所有三个即可。

如果您认为帮助文本仅提供“关于如何更改偶数页和奇数页的 header 的说明”,那您就错了。

没有“wdHeaderFooterOddPages”这样的枚举。

简而言之:

Sub Demo()
Dim HdFt As HeaderFooter
With ActiveDocument.Sections.Last
  For Each HdFt In .Headers
    HdFt.LinkToPrevious = False
  Next
  For Each HdFt In .Footers
    HdFt.LinkToPrevious = False
  Next
End With
End Sub

有关全面的解决方案,请参阅:https://www.msofficeforums.com/word-vba/43339-combine-multiple-word-documents.html。正如您从上面和 link 中的代码中看到的那样,也没有必要搞乱:

ActiveWindow.ActivePane.View.Type