Problem with cycling thru cells

R

Rick

I'm trying to insert a table in Word at the end of a
document. I want to add text in the cells of the first
row, format the width and then add data from a database
to the rows below it. (I can get the data) The table with
the correct # of rows is created at the end of the
document but Selection.Tables(TblIndex).Cell(1, 1).Select
gives me an error that the requested member of the
collection does not exist. The cursor is in the first
cell after table creation. If I remove this line of code,
Quantity is inserted but the cursor will not advance to
the next cell.

How can this be fixed? I'm using Word 98 and Word XP

CODE:

NumRows = NumRows + 3
ActiveDocument.Tables.AddSelection.Range,_
NumRows,4 '4 is the number of columns
TblIndex = ActiveDocument.Tables.Count
Selection.Tables(TblIndex).Cell(1, 1).Select
Selection.TypeText "Quantity"
Selection.Tables(TblIndex).Cell(1, 1).Width =
InchesToPoints(0.75)
Selection.Tables(TblIndex).Cell(1, 2).Select
Selection.TypeText "Description"
Selection.Tables(TblIndex).Cell(1, 2).Width =
InchesToPoints(3.5)
Selection.Tables(TblIndex).Cell(1, 3).Select
Selection.TypeText "Price Each"
Selection.Tables(TblIndex).Cell(1, 3).Width =
InchesToPoints(1)
Selection.Tables(TblIndex).Cell(1, 4).Select
Selection.TypeText "Ext. Price"
Selection.Tables(TblIndex).Cell(1, 4).Width =
InchesToPoints(1)
Selection.Tables(TblIndex).Rows(1).Shading.Texture =
wdTexture10Percent
 
D

Doug Robbins - Word MVP

Hi Rick

Dim atable as Table

Then

Set atable = ActiveDocument.Tables.Add

then don't screw around selecting cells, use

atable.cells(1, 1).Range = "Quantity"

etc.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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