In my workbook I want to show when a pivot table was last refreshed. I have code to refresh all pivot tables but also want to track when the user manually refreshes a pivot table.
To refresh all tables in code I am looping through all the worksheets in a workbook looking for those that have pivot tables. The code then calls RefreshTable on each pivot table in that sheet.
For Each wks In theDataWorkbook.Worksheets
theSheetName = wks.Name
If wks.PivotTables.Count > 0 Then
Debug.Print PROC_NAME & ": " & theSheetName
For i = 1 To wks.PivotTables.Count
wks.PivotTables(i).RefreshTable
Next i
End If
Next wks
I'm using the workbook event to respond when a pivot table is refreshed and then write a timestamp to the worksheet.
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
Debug.Print Sh.Name & " " & Target.Name
UpdatePivotTableRefreshedTimestamp(Target) ' This writes a timestamp to the sheet
End Sub
The workbook event is firing for each pivot table on the sheet even though only one has been updated. The event even fires for a different pivot table on another sheet. Why is this? The pivot tables uses the same Excel Data Table as their source.