need to skip the line that contains the text Word Macro

旧街凉风 提交于 2020-01-06 07:20:55

问题


I have to print documents and what it requires is:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!