0
我一直在Excel 2016(64位版本)中记录/写入宏。我需要在它的最后创建一个数据透视表。我在我的电脑上尝试了四种不同的方式,它们都可以工作。运行时错误5有时在VBA创建数据透视表
不过!当我将文件发送给其他用户时,数据透视表部分总是失败,并始终返回
运行时错误5:无效的过程调用或参数。
其他用户位于虚拟桌面(Windows 2008 R2)和Office 2013(32位版本)上。
我的确研究过这个问题,这就是为什么我在下面有很多不同的代码位,但不管我做什么,其他用户都得到了运行时错误5。再说一次,所有这些工作都是在我的电脑上按照预期工作的,所以我假设有一个版本问题,但我承认我在这一点上正在猜测。我错过了什么?
宏录制代码:
Range("A1").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table1", Version:=6).CreatePivotTable TableDestination:="Summary!R1C1", _
TableName:="PivotTable3", DefaultVersion:=6
最常见的修复我在网上找到:
Range("A1").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table1", Version:=6).CreatePivotTable TableDestination:="'Summary'!R1C1", _
TableName:="PivotTable3", DefaultVersion:=6
第二个最常见的修复我在网上找到:
Range("A1").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table1", Version:=6).CreatePivotTable TableDestination:=ActiveWorkbook.Worksheets("Summary").Range("$A$1"), _
TableName:="PivotTable3", DefaultVersion:=6
我甚至试图通过作弊将现有数据透视表导入新工作簿,然后更新数据透视表获取数据的位置,但我仍然保留我得到一个运行时错误5。
ActiveSheet.PivotTables("PivotTable3").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Table1", Version:=6)
6版是2016年的Excel也许你应该使用5版为Excel 2013? –
查看[PivotCaches.Create方法](https://msdn.microsoft.com/VBA/Excel-VBA/articles/pivotcaches-create-method-excel)及其对'Version'的枚举[[XlPivotTableVersionList Enumeration] (https://msdn.microsoft.com/VBA/Excel-VBA/articles/xlpivottableversionlist-enumeration-excel) –