我的问题是,取决于我选择文本的方向,从第5-10页还是从第10-5页,我得到了不同的结果。下面的代码从活动页面开始。
Sub setOdd()
Call editBrake("odd")
End Sub
Sub editBrake(typ As String)
Dim iSec As Long, iSecs As Long, iSecTot As Long, i As Long, s As Section
iSec = Selection.Information(wdActiveEndSectionNumber)
iSecs = iSec + Selection.Sections.Count - 1
iSecTot = ActiveDocument.Sections.Count
If iSecTot >= iSec Then
For i = iSec To iSecs
Set s = ActiveDocument.Sections(i)
If typ = "new" Then
s.PageSetup.SectionStart = wdSectionNewPage
ElseIf typ = "odd" Then
s.PageSetup.SectionStart = wdSectionOddPage
ElseIf typ = "even" Then
s.PageSetup.SectionStart = wdSectionEvenPage
End If
Next i
ElseIf iSecTot = 1 Then
MsgBox "There is no section breaks in document", vbInformation, "Change section breaks"
End If
End Sub
发布于 2022-08-05 15:38:59
只需通过循环遍历所选的部分来保持简单。
Sub editBreak(typ As String)
Dim s As Section
If ActiveDocument.Sections.Count > 1 Then
For Each s In Selection.Sections
If typ = "new" Then
s.PageSetup.SectionStart = wdSectionNewPage
ElseIf typ = "odd" Then
s.PageSetup.SectionStart = wdSectionOddPage
ElseIf typ = "even" Then
s.PageSetup.SectionStart = wdSectionEvenPage
End If
Next
Else
MsgBox "There are no section breaks in document", vbInformation, "Change section breaks"
End If
End Sub
发布于 2022-08-09 13:30:26
多亏了Timothy,下面的代码才能工作。(我也有一个Selection.Sections.Count = 1
代码)
Sub editBrake(typ As String)
Dim s As Section
Dim i As Integer
Dim skipFirst As Boolean
i = 1
If Selection.Sections.Count > 1 Then
skipFirst = True
For Each s In Selection.Sections
If skipFirst Then
skipFirst = False
Else
If typ = "new" Then
s.PageSetup.SectionStart = wdSectionNewPage
ElseIf typ = "odd" Then
s.PageSetup.SectionStart = wdSectionOddPage
ElseIf typ = "even" Then
s.PageSetup.SectionStart = wdSectionEvenPage
End If
End If
i = i + 1
Next
Else
MsgBox "There are no section breaks in document", vbInformation, "Change section breaks"
End If
End Sub
https://stackoverflow.com/questions/73247570
复制相似问题