dbowlds
07-25-2018, 03:30 AM
Hello, I have a need for a macro that inserts a simple, 2 column, 1 row table at the cursor location in a document. The table would have borders set to none, and the two cells would be formatted as a specific custom bullet style.
After lots of search the Internet for clues, I could not figure out how to insert and format such a simple table, so instead I decided it might be easiest to create the table I want as a building block (BB) and just have the macro insert it. I created and saved such a BB in my master template (the template that contains all my code). The BB is saved as the type: "Insert content in its own paragraph." Doing it this way ensures the table doesn't get inserted in the middle of a sentence.
However, if I run the code below, for some odd reason the building block table gets added to my document but with borders. Is there some way for the code to then immediately select the table and set the outside borders to none?
Any help would be most appreciated.
Sub rxbtnInsertBulletTable_click(control As IRibbonControl)
Dim MyTemplate As Template
Dim myBB As range
Dim myPath As String
myPath = Application.StartupPath & "\[template name]"
'Set the template to the one that holds the building block
Set MyTemplate = Templates(myPath)
With ActiveDocument
Set myBB = MyTemplate.BuildingBlockEntries("BulletTable").Insert _
(Where:=Selection.range)
'Select table just inserted and format the borders.style to none
End With
End Sub
After lots of search the Internet for clues, I could not figure out how to insert and format such a simple table, so instead I decided it might be easiest to create the table I want as a building block (BB) and just have the macro insert it. I created and saved such a BB in my master template (the template that contains all my code). The BB is saved as the type: "Insert content in its own paragraph." Doing it this way ensures the table doesn't get inserted in the middle of a sentence.
However, if I run the code below, for some odd reason the building block table gets added to my document but with borders. Is there some way for the code to then immediately select the table and set the outside borders to none?
Any help would be most appreciated.
Sub rxbtnInsertBulletTable_click(control As IRibbonControl)
Dim MyTemplate As Template
Dim myBB As range
Dim myPath As String
myPath = Application.StartupPath & "\[template name]"
'Set the template to the one that holds the building block
Set MyTemplate = Templates(myPath)
With ActiveDocument
Set myBB = MyTemplate.BuildingBlockEntries("BulletTable").Insert _
(Where:=Selection.range)
'Select table just inserted and format the borders.style to none
End With
End Sub