> Jonathan,
>
> Thanks for the reworked code. I tried it one statement at a time to
> understand what each statement did. I need a recommendation for a good
> book
> on VBA for Word.
Book reviews here
Book Recommendations
http://www.word.mvps.org/Tutorials/BookRecommendations.htm
> How is it that the Set oTable... statement actually creates a table rather
> than just storing it in oTable?
This line creates a table in the document
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=txtRows, _
NumColumns:=txtColumns
This line creates the same table in the document, and also says, in effect
"for the prupsoes of this macro, this table is called oTable. When you want
to refer to anything in this table, you can use this name."
If you know that the table is the first table in the document, then oTable
is exactly the same as ActiveDocument.Range.Tables(1). The advantage of usng
oTable this way is that you now have a reference to the table, wherever it
is, and it will continue to point to that specific table even if you insert
other tables elsewhere in the document.
>I could not find any online help that
> explained what Dim oTable as Table meant other than creating a variable.
Yes, it is creating an object variable. The specific object is a Table
obejct.
> In the next statement, it looks like oTable is an object and you are
> setting
> the style for the range that is the table. Did I get that right?
> oTable.Range.Style = "Table cell"
Pretty close. The oTable object has a Range property, which in turn is a
Range object which has a Style property, and we are assigning a new name for
that style.
> In the next statement that applies a style to the first row, I could not
> figure out how you came up with it.
> oTable.Range.Rows.First.Range.Style = "Table heading"
read backwards again. We are
- giving the name "Table heading"
- to the Style
- of the Range
- of the First
- Row
- of the range
- of the table pointed to by the oTable variable
(Actually, one of those ranges is superfluous, the Table objact has a Rows
property directly, we don't need a Range in there. So that line could be as
follows
oTable.Rows.First.Range.Style = "Table heading")
> I tried using the VBA trick of entering a string then a period and letting
> VBA prompt with a list of valid terms, but I could not quite figure out
> how
> you figured out the path.
Lots of practice :-)
> I have two other settings I would like to make:
> - setting the table indent
oTable.Rows.LeftIndent = CentimetersToPoints(1.5)
> - setting the table width
'set a fixed width
oTable.PreferredWidthType = wdPreferredWidthPoints
'decide what the width should be
oTable.PreferredWidth = CentimetersToPoints(16)
> I was able to figure out how to set the indent with
> oTable.Rows.LeftIndent = InchesToPoints(0.1)
> but I tried oTable.PreferredWidth = "4.75" for the table width and it
> jammed
> all the columns into the smallest width (less than an inch).
Almost every dimension is specified in points in Word VBA, and a table that
is only 4.75pt wide is pretty narrow!

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org