If you’re interested in using VBA (Visual Basic for Applications) to create tables in Microsoft Word, this tutorial is for you. You’ll learn how to create tables by specifying the number of rows and columns you want. Additionally, the tutorial will guide you on how to apply basic formatting and styling to the tables. By the end of the tutorial, you will be able to write and run VBA code that automatically creates tables in Word.

1. Creating a Single Table Using VBA Code
Open VBA Editor: by Pressing ALT + F11 shortcut key from you keyboard
Insert a new module: in VBA Editor click on insert, then select module and past the following VBA Code into the module.
Sub InsertTable()
Dim rows As Integer
Dim cols As Integer
Dim rowsInput As String
Dim colsInput As String
rowsInput = InputBox("Enter The Number of Rows you Want", "Rows")
colsInput = InputBox("Enter the Number of Columns that you Want", "Columns")
If rowsInput = "" Or colsInput = "" Then
MsgBox "Enter Number of rows or columns"
Else
On Error GoTo InvalidInput
rows = CInt(rowsInput)
cols = CInt(colsInput)
Dim table As table
Set table = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=rows, NumColumns:=cols)
table.Style = "Table Grid"
Exit Sub
InvalidInput:
MsgBox "Please enter valid numeric values for rows and columns."
End If
End Sub

After pasting the above-mentioned code into the module press CTRL+S (to Save your VBA Code), Press F5 (to directly run your code from VBA Editor) and close VBA Editor.
To use your VBA code to create tables, simply press the ALT + F8 keyboard shortcut. This will open the Macros dialog box, where you will see a list of all your created macros. From there select the macro you want to run and click the Run button.
2. Create a Specified Number of Multiple Tables in Word using VBA
By following VBA Code will allows you to create multiple tables in Microsoft Word by specifying the number of tables, rows, and columns. The user is prompted to enter the number of tables you want to create the number of rows and columns for each table. The code then automatically inserts the specified number of tables, with the given number of rows and columns, and applies a default table style (“Table Grid”) to each one. After each table is inserted, the cursor moves down to ensure that the next table is placed on a new line. This makes it easy to quickly and easily generate multiple tables in a Word document with consistent formatting.
Follow these Steps to Create Multiple Tables using VBA
- Open VBA Editor (By pressing ALT+F11)
- Create a New Module, past the following code into the module
Sub InsertMultipleTables()
Dim rows As Integer
Dim cols As Integer
Dim numTables As Integer
Dim rowsInput As String
Dim colsInput As String
Dim numTablesInput As String
Dim i As Integer
Dim currentRange As Range
numTablesInput = InputBox("Enter the number of tables you want to create", "Number of Tables")
rowsInput = InputBox("Enter The Number of Rows you Want", "Rows")
colsInput = InputBox("Enter The Number of Columns you Want", "Columns")
If numTablesInput = "" Or rowsInput = "" Or colsInput = "" Then
MsgBox "Please enter the number of tables, rows, and columns."
Else
On Error GoTo InvalidInput
numTables = CInt(numTablesInput)
rows = CInt(rowsInput)
cols = CInt(colsInput)
Set currentRange = Selection.Range
For i = 1 To numTables
' Insert the table
Dim table As table
Set table = ActiveDocument.Tables.Add(Range:=currentRange, NumRows:=rows, NumColumns:=cols)
table.Style = "Table Grid"
Set currentRange = table.Range
currentRange.Collapse Direction:=wdCollapseEnd
currentRange.InsertAfter vbCrLf
currentRange.Collapse Direction:=wdCollapseEnd
Next i
Exit Sub
InvalidInput:
MsgBox "Please enter valid numeric values for the number of tables, rows, and columns."
End If
End Sub

After Pasting the Code, Press CTRL+S (to save the VBA Code), Press F5 (to RUN VBA Code) and close VBA Editor.
I hope this tutorial will help to learn how to create tables in Microsoft Word using VBA Code. If you have any question, suggestion or feedback feel free to contact us using detail provided on our contact us page.
If you don’t know how to use and RUN VBA Code Visit the following link.
How to Use and Run VBA Code in Word, Excel, Access and PowerPoint
if you want to assign keyboard shortcut to your VBA Macros visit the following link.
How to Assign keyboard shortcut to VBA Coded Macros
FAQs – Creating Tables in Microsoft Word Using VBA
1. Can I create tables using VBA code in Microsoft Word?
Answer: Yes, absolutely! You can use VBA Code to create tables in Microsoft Word.
2. What is the shortcut key to open the VBA Editor in Word?
Answer: Press Alt + F11 on your keyboard to open the VBA Editor in Microsoft Word.
3. How can I insert and run VBA code to create a table?
Answer:
Follow these quick steps to create tables using VBA Code:
- Press Alt + F11 to open the VBA Editor.
- Go to Insert → Module.
- Paste your VBA code (for creating a single or multiple tables).
- Press Ctrl + S to save your code.
- Press F5 to run it directly from the VBA Editor.
- To run it later, press Alt + F8, select your macro from the list, and click Run.
4. What is the shortcut to open the Macros dialog box in Word?
Answer: Use Alt + F8 to open the Macros dialog box. This allows you to view, select, and run your existing VBA macros.
5. What is the shortcut key to run a VBA macro inside the VBA Editor?
Answer: Press F5 inside the VBA Editor to directly execute the active VBA procedure.
6. Can I create multiple tables using VBA?
Answer: Yes, you can create multiple tables using VBA Code.

