PDA

View Full Version : select/use active pivot, vba



pask
02-03-2009, 08:17 AM
I have made a macro that will automatically format an ordinary excel chart I have selected when I run the macro.

For this purpose, the following code works perfect:
With ActiveChart
.ChartTitle.Font.Size = 14
.Legend.Font.Size = 10
.Axes(xlCategory).TickLabels.NumberFormat = "[$-809]mmm-yy;@"
End With


However, I would like to make a separate macro to format a chart based on a pivot table (as these charts require somewhat different properties)

The "raw" code I have to do this, is the following:
ActiveSheet.PivotTables("PivotTable2").PivotFields("Date").Name = _
"[$-809]mmm-yy;@"

However, this will only work on the static pivot table name.

My question is:
How can I call on the currently selected pivot chart, regardless of name, but based on the one currently selected in the worksheet?

(I am running Office 2007 on Windows Vista)

Any help on this is highly appreciated.

Best regards
Paul