【问题标题】:Word VBA to change the header for one sectionWord VBA 更改一个部分的标题
【发布时间】:2019-06-04 16:06:20
【问题描述】:

所以在我的文档中,它会从 Access 中复制一些表格,然后将它们粘贴到 Word 中:

' Paste into word
wd.ActiveDocument.Sections(i).Range.Select
wd.Selection.Paste

然后它格式化表格,然后在最后插入一个分节符:

' Insert a new section
wd.ActiveDocument.Characters.Last.Select
wd.Selection.Collapse
wd.Selection.Range.InsertBreak Type:=wdSectionBreakNextPage

然后它重新开始循环:它从 Access 复制一个表并将其粘贴到新部分。我正在尝试更新这个新部分的标题,但它正在更新所有标题。

' Write to the header of this section
With wd.ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).Range
    .Text = Chr(10) & headerText
    .Font.Size = 18
    .Font.Name = "Tahoma"
    .Font.Bold = True
    .ParagraphFormat.SpaceBefore = 6
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
End With

关于我做错了什么的建议?

【问题讨论】:

  • .linktoprevious 应该是假的
  • 是的,做到了。
  • @Freeflow 你想提供一个答案以便我接受吗?我不想因此而受到赞扬。

标签: vba ms-word


【解决方案1】:

页眉和页脚中文本的连续性由 .LinkToPrevious 属性控制。可以为三种类型的 Header 和 Footer 中的每一种单独设置此属性。如果该属性设置为“True”,则当前页眉/页脚从先前相同类型的页眉/页脚继承文本。如果它设置为“False”,那么您可以在页眉/页脚中放置不同的文本。

【讨论】:

    猜你喜欢
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    相关资源
    最近更新 更多