How to have a Macro skip code if PivotTable/PivotField is not there

M

mholland88

Excel 2003 connected to an OLAP database. I am updating a PowerPoint
presentation that has 40 different PivotCharts in it. In these Charts
some have one Pivot Table others have two Pivot Tables. These charts
are updated monthly with different customer names and date ranges or
other varables.

I am trying to find a way to have the Macro look to see if this
PivotTable or PivotField is present if not then skip the code for it.
The Table names are all different. The Macro runs fine as long as the
charts have two pivot tables it errors out on the ones that only have
one Pivot Table. If I comment out the line for the second pivot table
it also runs fine but only updates the information in one pivot table.
This Macro is set up to loop through all the slides and update the
fields with the information I specify.

I have been trying to use an If Then statement but I have not been able
to get it to work, even the "On Error Resume Next" does not work.

Any Suggestions, I have only been playing around with Macros for a few
months so it is probally something I am overlooking.

Here is part of the Macro. The Macro was orginaly written by someone
else to update the database connections I am just modifing it to cut
down on the amount of time spent to generate these reports. Currenlty
each chart has to be opened and the fields manually changed. The
coding below has been gathered from me recording my actions in the
charts or from searching Google.

Dim aSheet As Object, aPivot As Object,
.....

If TypeName(aSheet) = "Worksheet" Then

For Each aPivot In aSheet.PivotTables
'Debug.Print aSheet.PivotTables(1).Name

On Error Resume Next

aSheet.PivotTables(1).PivotFields("[Platinum Name]").CurrentPageName =
"[Platinum Name].[All Platinum Name].[xxxx]"

aSheet.PivotTables(2).PivotFields("[Platinum Name]").CurrentPageName =
"[Platinum Name].[All Platinum Name].[xxxx]"

'Shows just three months of data from Oct to Dec

aSheet.PivotTables("PivotTable1").CubeFields(4).TreeviewControl.Drilled
= Array(Array(""), Array( _
'"[Date Closed Calendar].[All Date Closed
Calendar].[2005]"), Array("[Date Closed Calendar].[All Date Closed
Calendar].[2005].[Quarter 4]"))


aSheet.PivotTables("PivotTable1").CubeFields(4).TreeviewControl.Drilled
= _
Array(Array(""), Array( _
"[Date Closed Calendar].[All Date Closed Calendar].[2005]"),
Array( _
"[Date Closed Calendar].[All Date Closed
Calendar].[2005].[Quarter 4]"))
aSheet.PivotTables("PivotTable1").PivotFields("[Date Closed
Calendar].[Year]") _
.HiddenItemsList = Array("[Date Closed Calendar].[All Date
Closed Calendar].[]" _
, "[Date Closed Calendar].[All Date Closed Calendar].[2003]", _
"[Date Closed Calendar].[All Date Closed Calendar].[2006]", _
"[Date Closed Calendar].[All Date Closed Calendar].[2004]")
aSheet.PivotTables("PivotTable1").PivotFields( _
"[Date Closed Calendar].[Quarter]").HiddenItemsList = Array( _
"[Date Closed Calendar].[All Date Closed
Calendar].[2005].[Quarter 1]", _
"[Date Closed Calendar].[All Date Closed
Calendar].[2005].[Quarter 2]", _
"[Date Closed Calendar].[All Date Closed
Calendar].[2005].[Quarter 3]")
aSheet.PivotTables("PivotTable1").PivotFields("[Date Closed
Calendar].[Month]" _
).HiddenItemsList = Array("")

Next aPivot

Thanks for any help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top