简体   繁体   中英

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. 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.

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

Gets me Error 450 - Wrong number of arguments or invalid property assignment.

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).

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?

Thanks!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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