Macro to format all pivotcharts in a workbook
Jeremy,
Suggestion: After creating your Pivot Table, go back into 'Table
Options' and uncheck 'AutoFormat table'. This will stop Excel from
automatically reformatting the Pivot Table that you just took so much time to
format exactly as you want it.
Here's a macro to change the AutoFormat option in all your Pivot Tables in
the active workbook.
'/-------------------------------------/
Sub ChangeAutoFormatting()
Dim iSheets As Integer, x As Integer
Dim iPivot As Integer, _
strCurrentSheet As String
On Error GoTo Exit_ChgAutoFmt
'Count number of sheets in workbook
iSheets = ActiveWorkbook.Sheets.Count
'remember current sheet
strCurrentSheet = ActiveSheet.Name
If Windows.Count = 0 Then _
GoTo Exit_ChgAutoFmt
For x = 1 To iSheets
'go to a worksheet to change pivot tables
Sheets(x).Activate
'turn warning messages off
Application.DisplayAlerts = False
'change all pivot tables on
' this worksheet one at a time
For iPivot = 1 To _
ActiveSheet.PivotTables.Count
ActiveSheet.PivotTables(iPivot). _
HasAutoFormat = False
Next
'turn warning messages on
Application.DisplayAlerts = True
Next
'return to worksheet that
' you were originally at
Application.ActiveWorkbook. _
Sheets(strCurrentSheet).Activate
Exit_ChgAutoFmt:
Application.CommandBars("PivotTable"). _
Visible = False
Application.DisplayAlerts = True
End Sub
'/-------------------------------------/
HTH,
Gary Brown
"jeremy nickels" wrote:
You know how Pivotcharts lose their formatting when you refresh the pivot
table they are attached to? Well I set up a macro to re-format the charts,
but my code only formats the currently selected chart. How can I change my
code to update all the pivot charts in my workbook?
Here's the code I have right now:
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels Type:=xlDataLabelsShowValue, _
AutoText:=True, LegendKey:=False
ActiveChart.SeriesCollection(1).DataLabels.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
.Background = xlTransparent
End With
|