View Single Post
 
Old 02-12-2020, 09:51 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Well a quick part is just a saved table. Once you insert it in the document you could then add or delete columns.


Say your create and save a simple two row X one column table as quickpart in the tables gallery "Built-In" category of the Building Blocks.dotx file. You could then use something like this:

Code:
Sub InsertBuildingBlock()
Dim oTmp As Template
Dim oRng As Range
Dim oTbl As Table
Dim lngRows As Long, lngCols As Long
  Templates.LoadBuildingBlocks
  For Each oTmp In Templates
    If UCase(oTmp.Name) = "BUILDING BLOCKS.DOTX" Then
      Exit For
    End If
  Next oTmp
  If Not oTmp Is Nothing Then
    Set oRng = oTmp.BuildingBlockTypes(wdTypeTables).Categories("Built-in").BuildingBlocks("Basic Table").Insert(Where:=Selection.Range, RichText:=True)
    Set oTbl = oRng.Tables(1)
    oTbl.Cell(1, 1).Range.Text = InputBox("Enter the table title", "TITLE")
    lngRows = InputBox("Enter the number of rows", "ROWS", 1)
    lngCols = InputBox("Enter the number of columns", "COLUMNS", 2)
    oTbl.Cell(2, 1).Split lngRows, lngCols
    oTbl.Style = "Plain Table 1"
  End If
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote