M
Michael F
Hi,
I got some code from a userform for creating and formatting a table (found
it in an old Word template). After adding the table, it uses the Selection
object to select that table for formatting and then to select the top row for
formatting.
What is the proper method for selecting parts of a table you just created or
happen to be inside? I read somewhere on the MVPS.org site about not using
Selection so much. I tried using ActiveDocument.Tables(1).Rows(1).Select to
select a row but it kept jumping to the first table in the file or giving me
an error if I left out one of the index numbers. I don't understand how that
syntax works or even if it's possible to use ActiveDocument to select a table
or parts of one.
And of course the Word VBA online help told me nothing about how to add a
table or find parts of it.
Michael F.
' add a table using numbers from the form
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=txtRows, _
NumColumns:=txtColumns
'Select the entire table
Selection.Tables(1).Select
'And apply Table Cell style to all
Selection.Style = ActiveDocument.Styles("Table cell")
'select the first row and apply table heading style
'ActiveDocument.Tables(1).Rows(1).Select
Selection.Rows.First.Select
Selection.Style = ActiveDocument.Styles("Table heading")
'Leave cursor in first cell
Selection.HomeKey Unit:=wdLine
I got some code from a userform for creating and formatting a table (found
it in an old Word template). After adding the table, it uses the Selection
object to select that table for formatting and then to select the top row for
formatting.
What is the proper method for selecting parts of a table you just created or
happen to be inside? I read somewhere on the MVPS.org site about not using
Selection so much. I tried using ActiveDocument.Tables(1).Rows(1).Select to
select a row but it kept jumping to the first table in the file or giving me
an error if I left out one of the index numbers. I don't understand how that
syntax works or even if it's possible to use ActiveDocument to select a table
or parts of one.
And of course the Word VBA online help told me nothing about how to add a
table or find parts of it.
Michael F.
' add a table using numbers from the form
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=txtRows, _
NumColumns:=txtColumns
'Select the entire table
Selection.Tables(1).Select
'And apply Table Cell style to all
Selection.Style = ActiveDocument.Styles("Table cell")
'select the first row and apply table heading style
'ActiveDocument.Tables(1).Rows(1).Select
Selection.Rows.First.Select
Selection.Style = ActiveDocument.Styles("Table heading")
'Leave cursor in first cell
Selection.HomeKey Unit:=wdLine