Modify table cell in winword via automation

I'm filling in a winword document with a table via automation (VBA, access database).  The automation code moves to a bookmark and inserts text at that point.  Everything works perfectly.
Now there is a requirement to change the border of a cell that has a specific bookmark in the cell in a word table.  Two parts to the problem.
  • How do I identify and select the table cell based on it containing a bookmark?
  • Once I have the cell selected how would I modify one of the cell borders (change the line style)?
LVL 45
AndyAinscowFreelance programmer / ConsultantAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GrahamSkanConnect With a Mentor RetiredCommented:
Here is a some sample code:
Sub ModifyCellBorder()
    Dim cl As Word.Cell
    Dim doc As Document
    
    Set doc = ActiveDocument
    Set cl = doc.Bookmarks("MyBookmark").Range.Cells(1)
    cl.Borders(wdBorderLeft).LineStyle = wdLineStyleDashDot
End Sub

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
Thanks, I'll give it a try tomorrow and get back.
0
 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
Just needed to qualify doc as Word.Document and then worked perfectly.  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.