PDA

View Full Version : Word VBA: act on text selection only if text is formatted as “Bullet”



David.P
10-18-2014, 11:24 AM
Hi forum,

I am trying to make a Word VBA macro to only jump in and act if the currently selected text in the Word document (or the text where the cursor currently is placed, respectively) has a certain list style, namely the list style "Bullet" (wdListBullet).

I gather that the code should be something along these lines:


Sub Act_On_Bulleted_Text()
With Selection.Style
If .ListFormat.ListType = WdListType.wdListBullet
Then
[Do something]
Else
[Do something else]
End If
End With
End Sub

However, the query in the second and third lines above probably is not quite right yet.

Thanks already for reading, and for any hints in order to make the above code work,

Regards
David

gmaxey
10-19-2014, 05:15 AM
ub Act_On_Bulleted_Text()
With Selection.Paragraphs(1).Range
If .ListFormat.ListType = wdListBullet Then
.Font.ColorIndex = wdBrightGreen
Else
'Do That
End If
End With
End Sub

David.P
10-19-2014, 07:13 AM
Yesss! Thanks Greg! The code works like a charm!

This shall be my first step out of the Word numbering hell.

12413

Sorry am not allowed to post links...
goo.gl/Uco9LM
goo.gl/aSjkiJ