Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table in Word using Vba

Status
Not open for further replies.

vnk

IS-IT--Management
Nov 14, 2001
33
0
0
US
Hi,

Am trying to insert a table with 4 columns and 20 rows into
a word document and also fill data in few columns.

Can some one point me in the right direction to get this
done using VBA. I have tried referring to the help manual, but its no use.

Thanks In Advance
VNK
 
why not record a macro then look at the code generated?

Tools-->macros-->record macro
 
Justin,

Thanks, I have tried that before, but code is too
cumbersome.....there should be a nicer and neater way.

Thanks!
vnk
 
Try this:
With <word document object>
.Tables.Add Range:=.Parent.Selection.Range, _
NumRows:=<number of rows>, _
NumColumns:=<number of columns>, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitFixed
end with

M :)
 
Mossoft,

Thanks for your input, but at the same time I want to
insert the data. can we specify what to be written in
which column, using VBA.

Thanks once again.
vnk
 
Dim oTable As Table
Dim oCell As Cell

Set oTable = ActiveDocument.Tables(1)

Set oCell = oTable.Cell(Row:=2, Column:=2)

oCell.Range.Text = &quot;2x2&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top