首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改选定的部分

更改选定的部分
EN

Stack Overflow用户
提问于 2022-08-05 09:29:56
回答 2查看 47关注 0票数 0

我的问题是,取决于我选择文本的方向,从第5-10页还是从第10-5页,我得到了不同的结果。下面的代码从活动页面开始。

代码语言:javascript
运行
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-05 15:38:59

只需通过循环遍历所选的部分来保持简单。

代码语言:javascript
运行
复制
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
票数 1
EN

Stack Overflow用户

发布于 2022-08-09 13:30:26

多亏了Timothy,下面的代码才能工作。(我也有一个Selection.Sections.Count = 1代码)

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73247570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档