pelbooks
asked on
Splitting a table into columns using VBA in Word
Hello everyone.
I have this table in a doc file and I get some data in a recordset from an access file using vba. I want to display these data in the table but I want to add columns inside this table first and then put the data in the cells. Every time I want a different number of columns (depending on the data I got). How can I add columns and rows in a table? Thank you very much.
I have this table in a doc file and I get some data in a recordset from an access file using vba. I want to display these data in the table but I want to add columns inside this table first and then put the data in the cells. Every time I want a different number of columns (depending on the data I got). How can I add columns and rows in a table? Thank you very much.
ASKER
Dear Graham Skan
how can I add my table as an object variable? Thank you.
how can I add my table as an object variable? Thank you.
You will have to find it. Tables are indexed by their order in the document.
If it is the first, then you could do this
dim tbl as Table
tbl = doc.tables(1)
If it is the first, then you could do this
dim tbl as Table
tbl = doc.tables(1)
Sorry. Missed the Set.
dim tbl as Table
Set tbl = doc.tables(1)
dim tbl as Table
Set tbl = doc.tables(1)
ASKER
Hello again!
This works indeed but the columns go outside the predefined maximum width! Can't I create the columns without going over the maximum width? Thank you.
This works indeed but the columns go outside the predefined maximum width! Can't I create the columns without going over the maximum width? Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great thanks a lot :)
Sub AddRow(tbl As Table)
Dim rowObject As Row
Set rowObject = tbl.Rows.Add
End Sub
Sub AddColumn(tbl As Table)
Dim colObject As Column
Set colObject = tbl.Columns.Add
End Sub