nicemanda
nicemanda

Reputation: 91

How do I select multiple bullet lists within word macro

I am trying to find all instances of bulleted lists within a large selection of a word doc and assign them a style as per our company branding.

I have gotten pretty close, the following Macro selects the first line in the first bulleted list in the selection and assigns it the style I require.

I just need some help getting it to select all the bullets in the doc.

Sub findbullets22()
    'findbullets22 Macro
    Dim oPara As Word.Paragraph
    With Selection
        For Each oPara In .Paragraphs
            If oPara.Range.ListFormat.ListType = _
            WdListType.wdListBullet Then
                oPara.Range.Select
            End If
        Next
    End With
    Selection.Style = ActiveDocument.Styles("List Paragraph")
End Sub

Upvotes: 0

Views: 7301

Answers (3)

Suril Mehta
Suril Mehta

Reputation: 9

Below is a macro to select all bullets:

Sub SelectBullets()
On Error Resume Next
Dim Para As Word.Paragraph
With ActiveDocument
    .DeleteAllEditableRanges (-1)
    For Each Para In .Paragraphs
        If Para.Range.ListFormat.ListType > 0 Then
            Para.Range.Editors.Add (-1)
        End If
    Next
    .SelectAllEditableRanges (-1)
    .DeleteAllEditableRanges (-1)
End With
End Sub

Once selected, you can uniformly modify all bullets.

Para.Range.ListFormat.ListType > 0 - this command specifies that each and every type of bullet or numbered list is to be selected. Para.Range.Editors.Add (-1) - this command adds the relevant selection to range .SelectAllEditableRanges (-1) - this command selects all ranges added

For additional useful word macros, please visit my video available at the following link https://youtu.be/p_ZhufliFw8

Regards, Suril Mehta

Upvotes: 0

cbjayakumar
cbjayakumar

Reputation: 11

This might help you:

With seletion
     For Each oPara In ActiveDocument.Paragraphs
         If oPara.Range.ListFormat.ListType = WdListType.wdListBullet Then
            oPara.Range.Select
            oPara.style = ActiveDocument.styles("List Paragraph")
         End If
     Next
End With

Upvotes: 1

Siddharth Rout
Siddharth Rout

Reputation: 149277

Like this? You have to set style inside the loop and not outside the loop.

Sub findbullets22()
    Dim oPara As Word.Paragraph

    With Selection
        For Each oPara In .Paragraphs
            If oPara.Range.ListFormat.ListType = WdListType.wdListBullet Then
                oPara.Range.Style = ActiveDocument.Styles("List Paragraph")
                DoEvents
            End If
        Next
    End With
End Sub

Upvotes: 2

Related Questions