【发布时间】:2019-06-18 11:06:46
【问题描述】:
我必须达到的目标:
我的word文档中有两种数据,“摘要”和“版税”,在一个文档中可以有这两个部分的多个部分。但总是以相同的顺序“摘要->版税->摘要->版税”
- 我必须在每个摘要页面之后添加一个空白页面。总是最多一页。
- 对于版税,如果版税部分从第 2 页开始并在第 4 页结束,则意味着总页数为 3,在这种情况下,我必须在此之后添加一个空白页。
目前编写的代码如下:
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
我当前的代码如下:它检查版税部分的开始,并获取文档最后出现的版税部分的结尾,即问题,我想获取当前的版税部分。请帮忙。
【问题讨论】:
-
代码如何识别版税部分的结束位置?
-
我们将在它旁边有摘要部分。
-
所以又一次搜索摘要?
-
我想是的,如果我们找到它的下一个摘要,我猜它会起作用..
-
我们需要获取即将到来的Summary Page的页码,从中我们可以得到当前Royalty Section的总页数,并可以进行奇数校验