I'm trying to play around with setting up a table macro.
Any help would be greatly appreciated...I've spent hours on this problem and can't seem to solve it!
The goal is to ask the user the rows, columns, (done) and then format to a standard formatting template. (can't get working) Following this I wanted the User to enter the caption information in the caption.
As it stands I have some very BAD code that sort of does it... what I can't figure out is how to set a range for the table created.
1) How the formatting should loook:
The new table has a different 'style' from the rest of the text. The header should have style:'Header Text' and the rest of the cells should have the style: 'Table Text'.
I wanted to create a range of all the cells after the header and format it as 'Table Text' (this is what I've set up recursively). I'd rather set this up using the range and then apply the style I want for this range.
2) What I can't get:
I need to select the table without knowing the index of the table. I can't seem to figure this out. I wanted to set the various properties of the table but I have to know the 'index as a Long'. I don't know this number since the user will use the code to set up any number of tables, anywhere in the text.
3) Here's the code so far:
Dim enter_Rows As Integer
Dim enter_Columns As Integer
Dim count As Integer
Set aDoc = ActiveDocument
Any help would be greatly appreciated...I've spent hours on this problem and can't seem to solve it!
The goal is to ask the user the rows, columns, (done) and then format to a standard formatting template. (can't get working) Following this I wanted the User to enter the caption information in the caption.
As it stands I have some very BAD code that sort of does it... what I can't figure out is how to set a range for the table created.
1) How the formatting should loook:
The new table has a different 'style' from the rest of the text. The header should have style:'Header Text' and the rest of the cells should have the style: 'Table Text'.
I wanted to create a range of all the cells after the header and format it as 'Table Text' (this is what I've set up recursively). I'd rather set this up using the range and then apply the style I want for this range.
2) What I can't get:
I need to select the table without knowing the index of the table. I can't seem to figure this out. I wanted to set the various properties of the table but I have to know the 'index as a Long'. I don't know this number since the user will use the code to set up any number of tables, anywhere in the text.
3) Here's the code so far:
Dim enter_Rows As Integer
Dim enter_Columns As Integer
Dim count As Integer
Set aDoc = ActiveDocument
Code:
' function to get the number of rows and columns
Get_Rows_Columns Rows:=enter_Rows, Columns:=enter_Columns
Set New_Table = aDoc.Tables.Add( _
Range:=Selection.Range, _
NumRows:=enter_Rows, _
NumColumns:=enter_Columns, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitFixed)
If enter_Rows > 1 Then ' if greater than 1 that is
Selection.SelectRow
Selection.Style = aDoc.Styles("Table Header")
For count = 1 To (enter_Rows - 1)
Selection.MoveDown Unit:=wdLine, count:=1
Selection.SelectRow
Selection.Style = ActiveDocument.Styles("Table Text")
Next count
' With New_Table =
' Set Row_Range = aDoc.New_Table.Rows
' With Row_Range
End If
Selection.Move Unit:=wdRow, count:=-enter_Row ' this does not work
[\code]