【问题标题】:How to select all the paragraphs between two bullets vba如何选择两个子弹vba之间的所有段落
【发布时间】:2014-03-18 23:27:18
【问题描述】:

我在 MS Word 文档类型 wdListSimpleNumbering 中有一些项目符号,我无法找到一种方法来选择项目符号 u)v) 之间的所有段落。

例如在文档中,我有以下项目符号;

u) 公司介绍。

第一段

第二段

第三段

v) 公司愿景

现在我正在寻找一种方法来选择项目符号 u)v) 之间的段落。

使用以下代码;我可以用子弹u) 选择文本,但不确定如何选择直到子弹v) 的范围。这是我的代码:

For Each oPara In ActiveDocument.Paragraphs   
    If oPara.Range.ListFormat.ListType = wdListSimpleNumbering And _ 
       oPara.Range.ListFormat.ListString = "u)" Then _     
       oPara.Range.Font.ColorIndex = wdRed 
       oPara.Range.Select ' here I want to select paragraphs 
       Debug.Print (oPara)              
    End If
Next

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    这是一种方法:

    Sub TestSelectList()
    Dim oPara As Paragraph
    Dim bSelected As Boolean
    For Each oPara In ActiveDocument.Paragraphs
        If oPara.Range.ListFormat.ListType = wdListSimpleNumbering And _
                oPara.Range.ListFormat.ListString = "u)" Then ' Make sure to remove underscore for a multiline THEN.
            oPara.Range.Font.ColorIndex = wdRed
            oPara.Range.Select 
            ' Set a flag indicating that you are currently within the desired list item.
            bSelected = True
            Debug.Print (oPara)
        ElseIf bSelected And oPara.Range.ListFormat.ListType <> wdListSimpleNumbering Then
            ' If the flag is positive and the current paragraph is not of the simple list type, include it in the selection.
            Selection.MoveEnd wdParagraph
        ElseIf oPara.Range.ListFormat.ListType = wdListSimpleNumbering Then
            ' Otherwise, if the paragraph is of the simple list type, turn off the flag.
            bSelected = False
        End If
    Next
    End Sub
    

    这不适用于 u) 是列表中最后一项的情况,但我不确定你想在那里做什么,或者你怎么知道。

    【讨论】:

    • 感谢您的回答。我只想隐藏子弹下的所有文本)。因为我不想打印。
    猜你喜欢
    • 2021-05-10
    • 1970-01-01
    • 2021-09-06
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多