由于可旋转的caching,excel无法完成此任务

当我完成了我的excelmacros,我感到兴奋,然后我的老板递给我一个更大的文件来尝试和testing。 尺寸差异从15,000KB到275,000KB。 我只是希望它会继续运行。 我错了。 我得到“Excel无法完成此任务与可用资源”错误。 所以我们尝试在我的同事8core 16GB RAM机器上运行它。 想到这一点将会把它从公园里拿出来。 不。 这次在第二个数据透视表上也是一样的错误。 所以,我假设错误是在我的pivottable函数。 有没有办法来清理创build像清除caching或类似的东西?

Function CPT(ByRef Location() As String, Name As String, Data As String, ByRef Filters() As String, ByRef Rows() As String, ByRef Columns() As String _, ByRef Values() As String, ByRef Types() As String) ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ Data, Version:=xlPivotTableVersion15).createPivotTable _ TableDestination:=Worksheets(Location(0)).Range(Location(1)), TableName:=Name, _ DefaultVersion:=xlPivotTableVersion15 ActiveWorkbook.ShowPivotTableFieldList = True '///////////////////////////////////////////// 'If it errors field name is probably incorrect '///////////////////////////////////////////// 'Values If (Not IsArrayEmpty(Values())) Then For i = LBound(Values) To UBound(Values) If (Types(i) = "Max") Then ActiveSheet.PivotTables(Name).AddDataField ActiveSheet.PivotTables( _ Name).PivotFields(Values(i)), "Max of " & Values(i), xlMax ElseIf (Types(i) = "Sum") Then ActiveSheet.PivotTables(Name).AddDataField ActiveSheet.PivotTables( _ Name).PivotFields(Values(i)), "Sum of " & Values(i), xlSum ElseIf (Types(i) = "Min") Then ActiveSheet.PivotTables(Name).AddDataField ActiveSheet.PivotTables( _ Name).PivotFields(Values(i)), "Min of " & Values(i), xlMin ElseIf (Types(i) = "Count") Then ActiveSheet.PivotTables(Name).AddDataField ActiveSheet.PivotTables( _ Name).PivotFields(Values(i)), "Count of " & Values(i), xlCount End If Next i End If 'Filters If (Not IsArrayEmpty(Filters())) Then For i = LBound(Filters) To UBound(Filters) With ActiveSheet.PivotTables(Name).PivotFields(Filters(i)) .Orientation = xlPageField End With Next i End If 'Rows If (Not IsArrayEmpty(Rows())) Then For i = LBound(Rows) To UBound(Rows) With ActiveSheet.PivotTables(Name).PivotFields(Rows(i)) .Orientation = xlRowField .Position = 1 End With Next i End If 'Columns If (Not IsArrayEmpty(Columns())) Then For i = LBound(Columns) To UBound(Columns) With ActiveSheet.PivotTables(Name).PivotFields(Columns(i)) .Orientation = xlColumnField End With Next i End If End Function 

有一个更有效的方法来有一个数据透视表function? 我必须创造很多,所以我不想为每一个编码。