sophisticatedpenguin
Technical User
Hi,
I'm trying to write a macro to insert a table in Word based on user input for the no. of rows and columns, and then to format it in a certain way.
Below is my code so far (apologies if it's not very good, I'm not experienced at this!) I set up my own table style called "MWGtable" and I want to apply that to the whole table. Will what I have apply the formatting to the entire table that has just been inserted? If not, how do I get it to select the whole table, please?
Many thanks!
Katie
Dim rownumber As Long
Dim colnumber As Long
rownumber = InputBox("How many rows?")
colnumber = InputBox("How many columns?")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=rownumber, NumColumns:=colnumber, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "MWTtable" Then
.Style = "MWGtable"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
I'm trying to write a macro to insert a table in Word based on user input for the no. of rows and columns, and then to format it in a certain way.
Below is my code so far (apologies if it's not very good, I'm not experienced at this!) I set up my own table style called "MWGtable" and I want to apply that to the whole table. Will what I have apply the formatting to the entire table that has just been inserted? If not, how do I get it to select the whole table, please?
Many thanks!
Katie
Dim rownumber As Long
Dim colnumber As Long
rownumber = InputBox("How many rows?")
colnumber = InputBox("How many columns?")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=rownumber, NumColumns:=colnumber, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "MWTtable" Then
.Style = "MWGtable"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With