【问题标题】:need to skip the line that contains the text Word Macro需要跳过包含文本 Word Macro 的行
【发布时间】:2019-06-24 10:31:34
【问题描述】:

我必须打印文件,它需要的是:

  1. 摘要页应打印在单页上(实际上总是单页),但下一页打印在它的背面,即版税摘要。所以我们使用宏在每个摘要页面之后添加了一个空白页面。
  2. 如果“Royalty”以奇数结尾(例如从第 2 页开始,以 3 结尾表示总共 3 页),则需要添加一个空白页。因此,下一个摘要部分将在新页面上开始打印,而不是在结束页面的背面。

我到现在写的如下:

Sub Test()


InsertSectionBreaks "S U M M A R Y             "
  InsertSectionBreaks "R O Y A L T Y             "
End Sub

Sub InsertSectionBreaks(FindText As String)
  Dim FindRange As Word.Range, SectionRange As Word.Range
  Dim Found As Boolean

  Set FindRange = ActiveDocument.Content

  ' Find next section based on text, insert odd page section break just before
  FindRange.Find.ClearFormatting
  With FindRange.Find
    .Text = FindText
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Found = .Execute
  End With

  Do While Found
    'avoid adding a section break at beginning of document
    If FindRange.Information(wdActiveEndAdjustedPageNumber) > 1 Then
      Set SectionRange = FindRange.Duplicate
      SectionRange.Collapse wdCollapseStart
      SectionRange.InsertBreak Type:=wdSectionBreakOddPage
    End If
    FindRange.Collapse wdCollapseEnd
    Found = FindRange.Find.Execute
  Loop
End Sub

它工作正常,但在“摘要”或“版税”进入空白页之前,我在同一行中的公司名称。这是我得到的输出图片:

我不知道如何解决此问题,公司名称应保留在同一页面上。应该包括中间的空白页。请帮忙。

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    只需使用正确的分页符在奇数页或偶数页上开始下一页,您将不需要宏来添加空白页。

    【讨论】:

    • 我需要使用宏来完成。
    • @RamSingh 然后使用宏添加这些偶数/奇数特定分页符之一。使用宏记录器找出用于该目的的代码。请注意,您无需检查“版税”是否以奇数结尾。无论如何,分页符都会正确处理它。另外我认为您可以将它们永久添加到您的文档中(没有宏)
    猜你喜欢
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多