I am trying to remove the last bullet/item from a bulleted list in Word with VBA.
It is possible to get the empty items with the following code, but I don't know how to delete this items:
For Each List In ActiveDocument.ListParagraphs
If Len(List.Range.Text = 2) Then
'Delete this list Item
End If
Next
This is an example of the list:
- Item 1
- Item 2
- Item 3
I already tried to select the Item via Range.Text.Select, but that did not work.
Any suggestions are welcome, thank you in advance.
Edit:
The problem is to delete the entire list item, including the list bullet. list.Range.Delete does not work and it looks like that the macro is even crashing.
The message box appears only a single time, even if there are multiple occurrences in the Document, if I remove list.Range.Delete the box appears a single time for every empty item.
Dim list As Paragraph
For Each list In ActiveDocument.ListParagraphs
MsgBox Len(list.Range.Text)
If Len(list.Range.Text) = 2 Then
MsgBox "DELETE"
list.Range.Delete
End If
Next