Tenho um livro de exercícios com 20 mesas giratórias diferentes. Existe alguma forma fácil de encontrar todas as tabelas dinâmicas e actualizá-las em VBA?
Sim.
ThisWorkbook.RefreshAll
Ou, se a sua versão em Excel for suficientemente antiga,
Dim Sheet as WorkSheet, Pivot as PivotTable
For Each Sheet in ThisWorkbook.WorkSheets
For Each Pivot in Sheet.PivotTables
Pivot.RefreshTable
Pivot.Update
Next
Next
Este código VBA atualizará todas as tabelas/parâmetros pivot na pasta de trabalho.
Sub RefreshAllPivotTables()
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
End Sub
Outra opção não programática é:
Isto irá actualizar a tabela dinâmica cada vez que a pasta de trabalho for aberta.
Você tem uma coleção de PivotTables em um objeto VB Worksheet. Então, um loop rápido como este vai funcionar:
Sub RefreshPivotTables()
Dim pivotTable As PivotTable
For Each pivotTable In ActiveSheet.PivotTables
pivotTable.RefreshTable
Next
End Sub
Notas das trincheiras:
Boa sorte!