Add a row in a Word table

N

Newbie

Hello,
What would be the syntax to add a row in a table of a Word document that has
been created/opened by the VBA procedure ?
Thanks in advance
 
S

Shauna Kelly

Hi Newbie

Use something like this:

Sub CreateTable()

Dim wdTable As Word.Table
Dim wdRange As Word.Range

Set wdRange = ActiveDocument.Range
wdRange.Collapse wdCollapseEnd

Set wdTable = ActiveDocument.Tables.Add(Range:=wdRange, NumRows:=2,
NuMColumns:=3)

wdTable.Rows.Add


End Sub


You'll find that the macro recorder often gives you a good idea of the
objects and methods involved in doing something like this. For more
information, see
Creating a macro with no programming experience using the recorder
http://www.word.mvps.org/FAQs/MacrosVBA/UsingRecorder.htm
and
How to modify a recorded macro
http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
N

Newbie

Thanks again Shauna

Shauna Kelly said:
Hi Newbie

Use something like this:

Sub CreateTable()

Dim wdTable As Word.Table
Dim wdRange As Word.Range

Set wdRange = ActiveDocument.Range
wdRange.Collapse wdCollapseEnd

Set wdTable = ActiveDocument.Tables.Add(Range:=wdRange, NumRows:=2,
NuMColumns:=3)

wdTable.Rows.Add


End Sub


You'll find that the macro recorder often gives you a good idea of the
objects and methods involved in doing something like this. For more
information, see
Creating a macro with no programming experience using the recorder
http://www.word.mvps.org/FAQs/MacrosVBA/UsingRecorder.htm
and
How to modify a recorded macro
http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top