代码之家  ›  专栏  ›  技术社区  ›  Kamran

如何在VBA中选择特定项目符号

  •  2
  • Kamran  · 技术社区  · 11 年前

    我在Word文档中有很多项目符号。
    我只想选择一个特定的项目符号,即。 u) 并使其文本变为红色。
    我设法数出子弹的数量。但我不确定如何选择特定的子弹。

    Sub FindBullet()
    
    Dim oPara As Word.Paragraph
    Dim count As Integer
    count = 0
    
    'Select Entire document
    Selection.WholeStory
    
    With Selection
        For Each oPara In .Paragraphs
            If oPara.Range.ListFormat.ListType = WdListType.wdListSimpleNumbering Then
                count = count + 1
            End If
        Next
    End With
    'Gives the count of bullets in a document
    MsgBox count
    
    End Sub
    
    1 回复  |  直到 11 年前
        1
  •  2
  •   L42    11 年前

    试试看:

    Selection.WholeStory
    With Selection
        For Each oPara In .Paragraphs
            If oPara.Range.ListFormat.ListType = wdListSimpleNumbering Then _
                If oPara.Range.ListFormat.ListString = "u)" Then _
                    oPara.Range.Font.ColorIndex = wdRed
        Next
    End With
    

    你只是错过了 Liststring 返回 Numbering 价值
    希望这有帮助。