1
votes

I just can't figure out how to get VBA to start a bulleted list in Word. I've got some code that types out stuff into word, I can get font and paragraph formatting, no problem, but now I want to create a bulleted list. I've found the following code,

ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(2)

which should create a bulleted list of the second standard type, but all I can determine is to use it with a 'Range' command which causes the entire document to have the list applied to it. What I'd like to do is have it applied just to the new line that I'm having the code type, and then, at some point, be able to turn the list off, to be able to continue without the list being applied.

Thanks!

1

1 Answers

3
votes

This link should help you with your query:

VBA - Bullet Points

Basically this code applies it to a selection:

Selection.Range.ListFormat.ApplyBulletDefault

And this code adds it to the selected paragraph number (in this case paragraph 2):

Documents("MyDoc.doc").Paragraphs(2).Range.ListFormat _ 
 .ApplyBulletDefault

This code applies the Bullet points to a range of paragraphs:

Set myDoc = ActiveDocument 
Set myRange = myDoc.Range( _ 
 Start:= myDoc.Paragraphs(3).Range.Start, _ 
 End:=myDoc.Paragraphs(6).Range.End) 
If myRange.ListFormat.ListType = wdListNoNumbering Then 
 myRange.ListFormat.ApplyBulletDefault 
End If

Assuming you know the text that is being added, you can use the second example. If you don't know how many paragraphs are being added, then each time you create a new one, increment an integer by 1 and use that integer in the third example.

For Example:

Start:= myDoc.Paragraphs(2).Range.Start, _ 
End:=myDoc.Paragraphs(i).Range.End)