我必须打印文档,它需要的是:
我到目前为止所写的内容如下:
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
它可以正常工作,但是公司名称在“摘要”或“版税”出现在空白页上之前位于同一行。这是我得到的输出图片:
我不知道该如何解决,公司名称应保留在同一页面上。中间应包含空白页。请帮忙。