我在工作表上有两个数据透视表,我希望在工作表打开时自动刷新。我已将该宏放在该表中。但是,我在这行“oPivot.RefreshTable”
上收到错误Private Sub Worksheet_Activate()
Dim oSheet As Worksheet
Dim oPivot As PivotTable
Set oSheet = ActiveSheet
For Each oPivot In oSheet.PivotTables
oPivot.RefreshTable
Next oPivot
End Sub
答案 0 :(得分:0)
此方法有效:
Private Sub Worksheet_Activate()
Dim oPivot As PivotTable
Dim xlsheet As Worksheet
Set xlsheet = ActiveSheet
For Each oPivot In xlsheet.PivotTables
oPivot.PivotCache.Refresh
Next oPivot
End Sub