vaguirre
08-03-2007, 03:51 PM
Hello,
I'm using Windows XP/Word 2003.
I created a Table style type (Table IPC 01), recorded a macro to insert a 3 column table (Insert3ColTable) based on Table IPC 01, and made other formatting adjustments. It's working great.
I also need a macro to insert a 4 and 5 column table with the same formatting adjustments. So, I created a macro called Insert4ColTable, copied and pasted the code from Insert3ColTable, adjusted the number of cols, the .Columns.PreferredWidth, and counts. When it runs I get run-time error '4608': Value out of range. When I select debug it goes to bolded text below.
Sub Insert3ColTable()
'
' Insert3ColTable Macro
' Macro recorded 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(1.91)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Options.DefaultBorderLineWidth = wdLineWidth100pt
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
Sub Insert4ColTable()
'
' Insert4ColTable Macro
' Macro created 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(1.43)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
Sub Record2ColTable()
'
' Record2ColTable Macro
' Macro recorded 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(2.75)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Options.DefaultBorderLineWidth = wdLineWidth100pt
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
So, I recorded another macro to insert 2 columns and it works. Why doesn't Insert4ColTable work? :dunno
Thanks bunches!
Vicki
I'm using Windows XP/Word 2003.
I created a Table style type (Table IPC 01), recorded a macro to insert a 3 column table (Insert3ColTable) based on Table IPC 01, and made other formatting adjustments. It's working great.
I also need a macro to insert a 4 and 5 column table with the same formatting adjustments. So, I created a macro called Insert4ColTable, copied and pasted the code from Insert3ColTable, adjusted the number of cols, the .Columns.PreferredWidth, and counts. When it runs I get run-time error '4608': Value out of range. When I select debug it goes to bolded text below.
Sub Insert3ColTable()
'
' Insert3ColTable Macro
' Macro recorded 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(1.91)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Options.DefaultBorderLineWidth = wdLineWidth100pt
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
Sub Insert4ColTable()
'
' Insert4ColTable Macro
' Macro created 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(1.43)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
Sub Record2ColTable()
'
' Record2ColTable Macro
' Macro recorded 8/3/2007
'
Selection.Style = ActiveDocument.Styles("Table Text 09")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.Columns.PreferredWidth = InchesToPoints(2.75)
If .Style <> "Table IPC 01" Then
.Style = "Table IPC 01"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Options.DefaultBorderLineWidth = wdLineWidth100pt
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.Style = ActiveDocument.Styles("Table Head 10")
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Style = ActiveDocument.Styles("Body Text 0pt After")
End Sub
So, I recorded another macro to insert 2 columns and it works. Why doesn't Insert4ColTable work? :dunno
Thanks bunches!
Vicki