cannot set word column widths

G

Guest

Hey all

I generate a word document from an access script. I generate a new table
inside the new document. I preset the table with a specified number of
columns and rows (using variables from a form input) and then merge all
columns in the first two rows for headers I write there. Because of the
merging, it will not allow me to specify preferred column widths. A message
comes up stating that it cannot isolate those columns because there are cells
of different widths. Here's my code:

Set tblNew = docActive.Tables.Add( _
Range:=docActive.Range(Start:=0, End:=0), NumRows:=totalrows,
NumColumns:=totalcols)
intCount = 1
tblNew.Borders.OutsideLineStyle = wdLineStyleSingle
tblNew.Borders.InsideLineStyle = wdLineStyleSingle
docActive.Range(tblNew.Cell(1, 1).Range.Start, tblNew.Cell(1,
totalcols).Range.End).Cells.Merge
tblNew.Cell(1, 1).Range.InsertAfter Header
tblNew.Cell(1, 1).Range.Font.Name = "Helvetica"
tblNew.Cell(1, 1).Range.Font.Bold = True
tblNew.Cell(1, 1).Range.Font.Size = 18
tblNew.Cell(1, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter

docActive.Range(tblNew.Cell(2, 1).Range.Start, tblNew.Cell(2,
totalcols).Range.End).Cells.Merge
tblNew.Cell(2, 1).Range.InsertAfter Subhead
tblNew.Cell(2, 1).Range.Font.Name = "Helvetica"
tblNew.Cell(2, 1).Range.Font.Bold = True
tblNew.Cell(2, 1).Range.Font.Size = 16
tblNew.Cell(2, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter

tblNew.Cell(3, 1).Range.InsertAfter "Rank"
tblNew.Cell(3, 1).Range.Font.Name = "Helvetica"
tblNew.Cell(3, 1).Range.Font.Bold = True
tblNew.Cell(3, 1).Range.Font.Size = 7
tblNew.Cell(3, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
tblNew.Cell(3, 1).Range.Cells.VerticalAlignment = wdCellAlignVerticalBottom
tblNew.Cell(3, 1).Range.Borders(wdBorderRight).LineStyle = wdLineStyleNone

At this point I attempt to at least set preferred cell widths for these
cells - the first cell I set at .65 inches, the second at 2. As soon as the
second cell, 2nd column on 3rd row is written at 2 inches, the whole table
goes off the right margin because it auto sets all other cells (the contents
of which have not yet been written to it) at .95 inches as a default. So then
I tried setting column widths, but then I got the message described earlier.
So I set NO widths at all, and my page setup and margins are kept intact, but
the user then has to manually set the column widths in word.

Any ideas? I know this explanation probably sucks, but my brain is shutting
down.
Thanks for any help.
 
J

John Nurick

Two thoughts.

1) If the headers are full width, write them in ordinary paragraphs
before the table, hence avoiding the need to merge cells.

2) Set the column widths you need before merging the cells.
 
G

Guest

Thanks

1. The two top banners need to be in the table because they require the same
perimeter lines as the rest of the table. I'll see if I can separate them,
but I need the lines connecting so don't know if word will accomodate that
without some space between the two.

2. I tried setting the column widths before merging the cells, but as soon
as the merge occurred, all column widths reverted to a default of .97 inches.
VERY annoying.
 
J

John Nurick

I hate it when Word doesn't work the way I think it ought to. Best seek
advice in a Word forum, e.g. microsoft.public.word.tables or
microsoft.public.word.vba.general.
 

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