Write to MS Word Table

ian_w

Registered User.
Local time
Today, 23:31
Joined
Jun 13, 2006
Messages
64
Hi,

Sorry if this is in the wrong section, seems more VBA than Word...

Scenerio

I am trying to write to a preset table in a Word 97 document.

I have bookmarked the table and I can open the bookmark using VBA but I can't for the life of me figure out how I can reference individual cells in it?

Is what I am trying to do possible, I was thinking something along the lines of

Code:
.ActiveDocument.Bookmarks("Table1").Select
    
With .Selection

    .Cells("B2").Text = "Name"
    .Cells("B3").Text = "Address"

End With

Thanks
 
Tables are a collection in MS Word if you open the Word Application. Don't use a bookmark. If you know the order of appearance of tables in this document, you can put a number in it. Something like ...ActiveDocument.Tables(iTbl).Row(iRow).Column(iCol).

If you have a "normal" table with no merged cells, you can also do ....Column(iCol).Row(iRow) and still get the same effect.

It has been a while, so you should expect to have to look that up in Word help (NOT Access help) to see the objects in a Word document under the VBA reference for Word. The Tables collection should be listed among the collections.
 
Hi,

Thanks for you reply.

Sadly I have looked all through Word help(97) and I can't find anything regarding VBA.

Either I can't google very well or information on doing this is pretty thin on the ground :(
 
I managed to figure this out using pretty much what The_DOC_Man posted..

Code:
        .ActiveDocument.Tables(1).Cell(1, 2).Select
        .Selection.Text = [I]"Text you want inserted"[/I]
 
That looks familiar. I recall that Word has a Microsoft Word Visual Basic Reference, but I think you had to have installed Word to include that feature. Otherwise you aren't guaranteed to have gotten Word VBA

If you have a table selected from the Tables collection, it has "sub-collections" such as Rows and Columns. These two collections have .Count properties. You can also do .Rows(iRow) and .Columns(iCol) (My bad about spelling the row/column references without the "s" in the names - like I said, it has been a couple of years.)

You can also do some things like .Add (to either Rows or Columns collection), .Delete a row or column, and a few other Methods.
 

Users who are viewing this thread

Back
Top Bottom