What I have to achieve:
There are two types of data in my word document, "Summary" and "Royalty", can have multiple of these two section in one document. but always in same sequence "Summary -> Royalty -> Summary -> Royalty"
- I have to add a blank page after Every Summary page. that will always be of one page max.
- For Royalty, If the Royalty Section Starts page number 2 and ends on 4 means total count of the pages is 3, in this case i have to add a blank page after this.
Code Written till now is below:
Sub Add_Page_After_Summary()
'
' Add_Page_After_Summary Macro
' Add_Page_After_Summary
'
' Sample Code
ActiveDocument.Range.Select
Do
With Selection.Find
.Text = "S U M M A R Y "
.Execute
End With
If Selection.Find.Found Then
Selection.GoTo What:=wdGoToBookmark, Name:="\Page"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertBreak Type:=wdPageBreak
Else: GoTo nxt
End If
Loop
nxt:
ActiveDocument.Range.Select
Do
With Selection.Find
.Text = "R O Y A L T Y "
.Execute
End With
If Selection.Find.Found Then
Dim startpage As Integer
Dim endpage As Integer
startpage = Selection.Information(wdActiveEndPageNumber)
Selection.GoTo What:=wdGoToBookmark, Name:="\Section"
endpage = Selection.Information(wdActiveEndPageNumber)
Dim difference As Integer
difference = endpage - startpage
If difference Mod 2 > 0 Then
Selection.GoTo What:=wdGoToBookmark, Name:="\Section"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertBreak Type:=wdPageBreak
End If
Else: Exit Sub
End If
Loop
End Sub
My current code is doing as below: it checks the starting of Royalty Section and it fetchs the ending of the royalty section that occurs in last of document, that is issue, i want to get the current Royalty Section. Please help.