Macro for auto printing Pivot Table with multiple page fields

JayMW

New Member
Joined
Sep 4, 2009
Messages
2
Hi People,

I have a macro I use (below) for auto printing Pivot Tables, which works by selecting an instance of the page field, printing, and then moving onto the next instance in the page field - which works great, except for a problem I have encountered recently which I cant work out how to overcome..

My Pivot table has evolved and now has 3 page fields. The macro I use assumes only one page field is present on the Pivot table and uses that to print from. I can workaround this by elevating whichever page field I want to print from to the first page field in the table layout. But how can I change the coding of the macro below to actually target a specific page field, I presume we could name the page fields and then tell the macro to target this instead of the first page field.

The name of the page field I am trying to print from is 'Stores'


Code:
Sub PrintAll()
    ' Find name of page field
    PageField1 = ActiveSheet.PivotTables("PivotTable1").PageFields(1)
    ' Determine how many pages there are in page field
    NumPages = ActiveSheet.PivotTables("PivotTable1").PivotFields(PageField1).PivotItems.Count
    For i = 1 To NumPages
        ThisPage = ActiveSheet.PivotTables("PivotTable1").PivotFields(PageField1).PivotItems(i)
        ActiveSheet.PivotTables("PivotTable1").PivotFields(PageField1).CurrentPage = ThisPage
        ActiveWindow.SelectedSheets.PrintOut
    Next i
End Sub

Much appreciated, as always
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top