简体   繁体   English

将Excel 2011宏中的VBA中的计算字段添加到Excel 2003书籍中的数据透视表中

[英]Adding calculated field from VBA in an Excel 2011 macro to a pivot table in an Excel 2003 book

I have a macro running in an Excel 2011 workbook that is manipulating a pivot table in an Excel 2003 book. 我在Excel 2011工作簿中运行一个宏,该宏正在处理Excel 2003图书中的数据透视表。 So far I haven't add issues with adding or hiding fields. 到目前为止,我还没有添加或隐藏字段的问题。

I'm trying to add a calculated field (as here - http://msdn.microsoft.com/en-us/library/ff834479(v=office.14).aspx ) and it is not working. 我正在尝试添加一个计算字段(如此处-http: //msdn.microsoft.com/zh-cn/library/ff834479 ( v=office.14 ) .aspx ),但它不起作用。

ws.PivotTables("RetailerMgmt").CalculatedFields.Add "ASP", " = TYDSMTD/TYUSMTD", FALSE

Gets me Error 450 - Wrong number of arguments or invalid property assignment. 使我得到错误450-错误的参数数量或无效的属性分配。

When I recorded the same task, the result was: 当我记录相同的任务时,结果是:

ExecuteExcel4Macro "(""RetailerMgmt"",1,""ASP"",""=TYDSMTD/TYUSMTD"",TRUE)"

Which was recorded and saved in the 2003 file, so I'm sure it's some Excel 2003 business (doesn't work when run from 2011). 该文件已记录并保存在2003文件中,因此我确定这是Excel 2003的一项业务(从2011年开始运行将无法使用)。

So, is there any way to add a calculated field to a pivot table in a 2003 workbook from a macro being run in a 2011 workbook? 因此,是否有任何方法可以从2011工作簿中运行的宏向2003工作簿中的数据透视表添加计算字段?

Thanks! 谢谢!

最后,我发现将源数据书另存为宏中的.xlsx文件,然后从那里进行处理变得更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM