Use macro recorder. Invoke the recorder, then complete the steps to copy and paste the table, then you can edit it to see the macro's actual instructions. But note that macro recorder does not save the contents of the clipboard, so the markup that creates the table will not be saved with the macro. To get it work, the table should exist before you run the macro.
Here is one possible method:
Before you start recording the following conditions should be met:
- Your table should be at the
beginning of the document after a
paragraph mark
- Your cursor should be
where you want to place the new
table
Then turn recording on and complete the following steps:
- Type
_table_goes_here_
where the
cursor is
- Press Ctrl + Home to go to the beginning of the document (just
before the main table
- Hold down
Shift
and press down arrow
key enough times until the
whole table is selected,
- Press Ctrl + C to copy the table
- Press Ctrl + F to bring up the Find dialog
- Type the placeholder text into Find what box (
_table_goes_here_
)
and click Find next
- When you have your placeholder text found and selected, press Esc
key to dismiss the find dialog
- Press Ctrl+V to paste the copied table which will replace your
placeholder text
- End macro recording.
Edit - Second approach
Another approach is to start macro recording and then create the table from scratch, that way you will not need a pre-existing table for the macro to work. When you have shaped and formatted the table end recording and you have captured all the required steps to place the exact same table wherever you want.
I just tested the second approach and it works just fine. Here is the code generated by the recorder for my small test:
Sub MakeTable()
'
' MakeTable Macro
' Macro recorded þ16þ/08þ/2010 by Majid Fouladpour
'
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
With Selection.Tables(1)
.Style = "Table Columns 4"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.TypeText Text:="Col one"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Col two"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Col three"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Col four"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="Item 1"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="Item 2"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="Item 3"
End Sub