Hello All,
I am trying to create a macro that will create a table style with a thin black line around the table and header cells, dashed grey lines separating cells in the body, and header text bold. I recorded a macro creating the table style format I want, then renamed the style I created and ran the recorded macro. The table style created by the recorded macro does not look the same as the style I created when recording it. The style produced by the recorded macro does not have any of the borders I created, but I can't tell why when I look at the code. An example spreadsheet with the table style I created and the one produced by the recorded macro is attached, and the recorded code is below. I would be greatly appreciated if someone would explain why the macro isn't producing what I expected and/or point me the right direction for how to get a macro to produce what I'm looking for.
Thanks
TableStyleExampleWorkbook.xlsm
Sub CreateTableStyleTest()
'
' CreateTableStyleTest Macro
'
'
ActiveWorkbook.TableStyles.Add ("NewTableStyle1")
With ActiveWorkbook.TableStyles("NewTableStyle1")
.ShowAsAvailablePivotTableStyle = False
.ShowAsAvailableTableStyle = True
.ShowAsAvailableSlicerStyle = False
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlEdgeTop)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlEdgeBottom)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlEdgeLeft)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlEdgeRight)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlInsideVertical)
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.349986266670736
.Weight = xlThin
.LineStyle = xlContinuous
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlWholeTable).Borders(xlInsideHorizontal)
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.349986266670736
.Weight = xlThin
.LineStyle = xlContinuous
End With
ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements(xlHeaderRow). _
Font.FontStyle = "Bold"
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlEdgeTop)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlEdgeBottom)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlEdgeLeft)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlEdgeRight)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlInsideVertical)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
xlHeaderRow).Borders(xlInsideHorizontal)
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
.LineStyle = xlNone
End With
End Sub
Bookmarks