Word VBA - Delete text from bulleted paragraphs

Joined
Feb 2, 2021
Messages
3
Reaction score
0
Hello!

I created a small macro (VBA) to delete the paragraphs that contain a bullet or picture bullet.
Problem is, it takes roughly 45 minutes for a 1 MB document with 277 pages (i can see Word struggling!).

Also, if a paragraph (with bullet) has a second paragraph (this one without bullet), the routine doesn't delete that second one.

Could someone kindly give me a hint on how to improve this routine? Or maybe another method to do this in a faster fashion?
Thanks in advance!

Code:
'Deletes whole text when a paragraph has a bullet
Sub DelParaTextBullet()
    Dim Para As Paragraph
    Dim ParaText As String
    For Each Para In ActiveDocument.Content.Paragraphs
        DoEvents
        If Para.Range.ListFormat.ListType = wdListBullet Or _
           Para.Range.ListFormat.ListType = wdListPictureBullet Then
            ParaText = Trim(Para.Range.Text)
            If ParaText <> Chr(13) Then
                Para.Range.SetRange Para.Range.Start, Para.Range.End - 1
                Para.Range.Select
                Selection.MoveLeft wdCharacter, Count:=1, Extend:=wdExtend
                Selection.Delete
            End If
        End If
    Next
End Sub
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
For example:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Format = True
.Forward = True
.Style = "List Paragraph"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top