Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2020, 08:37 AM
Dont know Dont know is offline VBA coding to insert a word table using  quickparts and insert table menu Windows 10 VBA coding to insert a word table using  quickparts and insert table menu Office 2016
Novice
VBA coding to insert a word table using  quickparts and insert table menu
 
Join Date: Feb 2020
Posts: 5
Dont know is on a distinguished road
Default VBA coding to insert a word table using quickparts and insert table menu

Can anyone give me some VBA coding advice to select one of many listed quickparts table place holder and then Add a title msgbox and source to be completed and "insert table" menu to select number of columns and rows. I have my default table style set up to apply styles.



Thanks
Reply With Quote
  #2  
Old 02-12-2020, 08:54 AM
gmaxey gmaxey is offline VBA coding to insert a word table using  quickparts and insert table menu Windows 10 VBA coding to insert a word table using  quickparts and insert table menu Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

To insert a named building block from the Built-In Building Blocks.dotx file you can use:

Code:
Sub InsertBuildingBlock()
Dim oTmp As Template
  Templates.LoadBuildingBlocks
  For Each oTmp In Templates
    If UCase(oTmp.Name) = "BUILT-IN BUILDING BLOCKS.DOTX" Then
      Exit For
    End If
  Next oTmp
  If Not oTmp Is Nothing Then
    oTmp.BuildingBlockTypes(wdTypeTables).Categories("Built-in").BuildingBlocks("With Subheads 1").Insert Where:=Selection.Range, RichText:=True
  End If
lbl_Exit:
  Exit Sub
End Sub

You could create your own custom building block in that template or gallery with the correct title and number of rows/columns.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 02-12-2020, 09:33 AM
Dont know Dont know is offline VBA coding to insert a word table using  quickparts and insert table menu Windows 10 VBA coding to insert a word table using  quickparts and insert table menu Office 2016
Novice
VBA coding to insert a word table using  quickparts and insert table menu
 
Join Date: Feb 2020
Posts: 5
Dont know is on a distinguished road
Default

Thanks for your reply.

I would like the user to be able to select which quickpart table to use as we have many options, so would like a message box to appear listing options to choose from then add how many rows and columns as these vary and not set.
Reply With Quote
  #4  
Old 02-12-2020, 09:51 AM
gmaxey gmaxey is offline VBA coding to insert a word table using  quickparts and insert table menu Windows 10 VBA coding to insert a word table using  quickparts and insert table menu Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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
Reply

Tags
insert word table, vba, word vba macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA coding to insert a word table using  quickparts and insert table menu Insert Excel cells Word Table BUT Fit? markg2 Word Tables 9 02-09-2020 02:25 PM
Insert a Excel table in an existing PowerPoint table Vallin PowerPoint 1 03-09-2015 06:25 AM
VBA coding to insert a word table using  quickparts and insert table menu Insert a Word Table into an Excel cell Kapoof Excel 1 02-18-2014 02:12 PM
VBA coding to insert a word table using  quickparts and insert table menu Word 2007: Insert Para after Table rphox2003 Word 10 03-06-2013 11:13 PM
Insert table in document - automatically updates second table in summary? Mechanic Word 2 08-01-2012 09:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft