我有8个数据透视表我试图刷新数据库缓存以使用宏(相同的源)。每个数据透视表都命名为PivotTableWPI1,PivotTableWPI2,...,PivotTableWPI8。所以我写了一个For循环来做到这一点。
我收到运行时错误'1004':应用程序定义或对象定义错误
Private Sub resetPivotCache()
Dim wb As Workbook
Set wb = ThisWorkbook
Dim pSheet As Worksheet
Set pSheet = wb.Sheets("Pivot")
Dim i As Integer
For i = 1 To 8
pSheet.PivotTables("PivotTableWPI" & i).PivotCache.Refresh
Next i
End Sub
我实际上也尝试过以下表格:
Private Sub resetPivotCache()
Dim wb As Workbook
Set wb = ThisWorkbook
Dim pSheet As Worksheet
Set pSheet = wb.Sheets("Pivot")
Dim i As Integer
With pSheet
For i = 1 To 8
PivotTables("PivotTableWPI" & i).PivotCache.Refresh
Next i
End With
End Sub
仍然会抛出相同的错误。有任何想法吗?提前谢谢。