Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mixing Text and Bulleted List in Word Table Cell with VBA

Status
Not open for further replies.

Caper1964

MIS
Mar 17, 2016
2
PL
Greetings,

I'm using VBA to create a MS Word table and am trying to populate a single cell with a mixture of regular text ("First line of text") and a bulleted list underneath ("Bulleted List 1", etc). When I run the following snippet it applies bulleting to the entire contents of the cell, not just the last paragraph. Any help getting me on the right track would be appreciated!

tbl1.Cell(5, 2).range.InsertAfter "First line of text"
tbl1.Cell(5, 2).range.InsertParagraphAfter
tbl1.Cell(5, 2).range.InsertAfter "Bulleted List 1" & vbNewLine & _
"Bulleted List 2" & vbNewLine & _
"Bulleted List 3" & vbNewLine & _
"Bulleted List 4" & vbNewLine
With tbl1.Cell(5, 2).range.Paragraphs.Last
.range.ListFormat.ApplyBulletDefault
End With
 
With tbl1.Cell(5, 2).range.Paragraphs.Last <--- this does not change the range
.range.ListFormat.ApplyBulletDefault <--- so here range is still the entire cell.
End With

Try

Set NewRange = tbl1.Cell(5, 2).range.Paragraphs.Last
NewRange.ListFormat.ApplyBulletDefault
 
Try:
Code:
Dim tbl1 As Table, Rng As Range
Set tbl1 = ActiveDocument.Tables(1) '(or whatever)
Set Rng = tbl1.Cell(5, 2).Range
With Rng
  .End = .End - 1
  .InsertAfter "First line of text" & vbCr
  .Collapse wdCollapseEnd
  .InsertAfter "Bulleted List 1" & vbCr & "Bulleted List 2" & vbCr & _
 "Bulleted List 3" & vbCr & "Bulleted List 4" & vbCr
 .ListFormat.ApplyBulletDefault
End With

Cheers
Paul Edstein
[MS MVP - Word]
 
Caper1964 (that was a good year :) ),
As this is a VBA question, you should be asking this question in forum707

Welcome to Tek-Tips. Enjoy :)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top