VBA to Print Charts, Error 1004 Unable to set Default Property of Pivot Item Class

I am running into an error when trying to execute this macro.  The error occurs at the following line of code:
      pt.PivotFields(pf.Name).CurrentPage = pi.Name
I recieve runtime error '1004": Unable to set the Default property of the pivot class.

How do I resolve this?
Sub PrintPivotCharts()
 'prints a chart for each item in the page field
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveChart.PivotLayout.PivotTable
  For Each pf In pt.PageFields
    For Each pi In pf.PivotItems
      pt.PivotFields(pf.Name).CurrentPage = pi.Name
'      ActiveSheet.PrintOut
      ActiveSheet.PrintPreview
      'print preview for testing
    Next
  Next pf
End Sub

Open in new window

kreepaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jeveristCommented:
Hi kreepa,

Hmm... It works fine for me with an active PivotChart.  Are you sure you have a PivotChart (with a Page field) that is active?

Jim
0
kreepaAuthor Commented:
I believe so. There is a page field named "Resources". This is the page that should be scrolled through and printed.
0
jeveristCommented:
kreepa,

Yeah, it looks like you have some old, unused PivotItems in there that need to be deleted.  Try this:

Sub PrintPivotCharts()
 'prints a chart for each item in the page field
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveChart.PivotLayout.PivotTable

  For Each pf In pt.PageFields
 
    On Error Resume Next
    For Each pi In pf.PivotItems
        pi.Delete
    Next pi
    On Error GoTo 0
   
    pt.RefreshTable
   
    For Each pi In pf.PivotItems
      pt.PivotFields(pf.Name).CurrentPage = pi.Name
'      ActiveSheet.PrintOut
      ActiveSheet.PrintPreview
      'print preview for testing
    Next
  Next pf
End Sub

Jim
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

kreepaAuthor Commented:
My pivot contains data in the following areas:

Page = Resource (About 20 items)
Column = Options (ie Active, Approved, MIN, MAX) Regarding Each Resourrce
Data = Months (13 months) or so
Row is Blank
0
kreepaAuthor Commented:
Excellent!!!!!!!!!!
0
kreepaAuthor Commented:
Fast and effective. I appreciate your time. I was banging my head against the desk for two hours and you were able to complete this in minutes.
0
jeveristCommented:
kreepa,

Glad to help and thanks for the grade!

Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.