Changing PivotTable data source to named range with VBA

manlypeeps

New Member
Joined
Nov 19, 2009
Messages
1
Hi,

I have a Java application that Excel files to users. However, I have a problem when a users chooses to open a file that includes a pivot table without saving it locally beforehand (and so it is downloaded to the user's temp folder) as Excel thinks its data source is external - even though the pivot table is getting its data from a named range that points to another sheet in the same workbook.

I thought I had a solution with the following code that basically refreshes the pivot table's source to the correct named range:

Worksheets(sCurrentSheet).Range("A5").PivotTable.ChangePivotCache ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=sPivotRange, Version:=xlPivotTableVersion10)

However, this only appears to work with Excel 2007. When a user tries to open a file with Excel 2003, the error message 'Runtime error 438: Object doesn't support this method or property' is displayed. I'm guessing that it has something to with the ChangePivotCache method as I can't see it in the Excel 2003 help.

I don't want to have delete the existing pivot tables (as each file can contain multiple pivot tables), so is it possible to replace the existing pivot table cache with a new named range?

Any help is much appreciated as this is driving me insane!

Steve
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top