L
Lisa
Hi,
I've created a custom button that runs a macro that adds a table into my
document and formats it using a specific style. Works great. Only issue is if
I select an existing table and run the macro it breaks (I get run time error
6028 the range cannot be deleted). I'm pretty new to this so I'm not sure how
to fix the code so that if someone tries to run it on an existing table they
have selected it won't crash and instead just applies the style BodyTable.
The code as it stands is:
Sub TableInsert()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "BodyTable" Then
.Style = "BodyTable"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Style = ActiveDocument.Styles("BodyTable")
End Sub
Any suggests would be greatly appreciated
Thanks
Lisa
I've created a custom button that runs a macro that adds a table into my
document and formats it using a specific style. Works great. Only issue is if
I select an existing table and run the macro it breaks (I get run time error
6028 the range cannot be deleted). I'm pretty new to this so I'm not sure how
to fix the code so that if someone tries to run it on an existing table they
have selected it won't crash and instead just applies the style BodyTable.
The code as it stands is:
Sub TableInsert()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "BodyTable" Then
.Style = "BodyTable"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Style = ActiveDocument.Styles("BodyTable")
End Sub
Any suggests would be greatly appreciated
Thanks
Lisa