问题
I have to print documents and what it requires is:
- Sumarry page should print on single page(always a single page actually) but the next page gets printed over it's back i.e. royalty Summary. so we added a blank page after every Summary page using Macro.
- If "Royalty" is ending on a Odd number(example starting at page number 2 and ending on 3 means total 3 pages), then need to add a empty page. So the next summary section will start printing on a new page not at the back of ending page.
what i have write till now is as below:
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
It works fine, but the company name i have in same line before the "Summary" or "Royalty" gets on the blank page. here is the pic of the output i am getting:
I'm not getting how this can be fixed, company name should remain on same page. should include blank page in between. please help.
回答1:
Just use the correct page break to start next page on an odd or even page and you will need no macro to add blank pages.
来源:https://stackoverflow.com/questions/56734697/need-to-skip-the-line-that-contains-the-text-word-macro