Link to home
Start Free TrialLog in
Avatar of Davisron867
Davisron867Flag for United States of America

asked on

"With Events" class to capture "After Pivot Table Refresh" event

Experts, Masters and Sages: Is there a way to create an After Pivot Table Refresh event (not Query Refresh) to fire additional code afterwards?

I have multiple users working in local Read Only copies of an Excel file with Pivot Tables sourcing an Access table. Users refresh their Pivot Tables using the Excel Menu or Context Menu.

After the Pivot refresh, I'll fire additional code to update a "Last Refresh Timestamp" that I compare to the "Data Source Timestamp". When Data Source is updated, the Data Source Timestamp > Last Refresh Timestamp and causes formula "=If(Last refresh > Data Source, "", "Update Available")" to display "Update Available".

When users subsequently Refresh, I want the code to update the last refresh Timestamp and the formula then returns a 0-length string and the notification goes away.

I did ask the question recently but accepted an incorrect answer, ID: 26237589
Avatar of steverice
steverice

You could add a new macro - fired by a button in the sheet, to update the pivot and then refresh the date/timestamp

Steve
Avatar of Patrick Matthews
Hello Davisron867,

Each worksheet has a PivotTableUpdate event, and there is a workbook-level SheetPivotTableUpdate event.

Regards,

Patrick
Avatar of Davisron867

ASKER

For the SheetPivotTableUpdate event to work, it appears you need to EnableEvents.
Private Sub Workbook_Open()
Application.EnableEvents = True
End Sub

And then the following executes once for each pivot table in the workbook.

Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
With Sheet6.Range("B7")
    .FormulaR1C1 = "=[MGMTREP_LEDGER_BAL.xlsm]Parameters!R7C2"
    .NumberFormat = "[$-409]m/d/yy h:mm AM/PM;@"
End With
Sheet6.Cells(7, 3) = Now()
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
negative...I have 5 pivot tables and it runs 5 times in succession, moving from one to the next as if in a loop.
Davisron867,

If your PTs are based off of other PTs, when the "parent" updates so will the children.

Also, if your PTs are set to refresh on open, when you open the file, they will refresh.

Do you have other code that is forcing refreshes?

Patrick
In fact I was turning off events somewhere.