I'm trying to create a new Pivot Table that has a connection to an existing External Data connection.
I've tried using the Macro Recorder, but running the sub doesn't work it jut errors wih
Run-time error '1004':
[Microsoft][ODBC Excel Driver] The connection for viewing your linked Microsoft Excel worksheet was lost.
I guess that the recorder isn't recording some important stage in the process.
The recorded code is
Can anyone advise what the code shoud be?
If it makes a difference, the External Connection is to a table in another Excel workbook.
(The connection has been created by VBA, and can post the code if it helps)
Also, can I omit the DefaultVersion so that it will be created with the version appropriate to the Excel version?
The code will likely be run on Excel 2007 onwards, but I wont know which.
Or will I need to discover the xcel version and then select the correct pivottableversions
Thanks
Kris
PS I did post this on Microsoft Answers, but the answer was to ask on another forum!!
I've tried using the Macro Recorder, but running the sub doesn't work it jut errors wih
Run-time error '1004':
[Microsoft][ODBC Excel Driver] The connection for viewing your linked Microsoft Excel worksheet was lost.
I guess that the recorder isn't recording some important stage in the process.
The recorded code is
Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("Query from Drill Sheet Database"), Version:= _
xlPivotTableVersion14).CreatePivotTable TableDestination:="Sheet1!R1C1", _
Tablename:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
Can anyone advise what the code shoud be?
If it makes a difference, the External Connection is to a table in another Excel workbook.
(The connection has been created by VBA, and can post the code if it helps)
Also, can I omit the DefaultVersion so that it will be created with the version appropriate to the Excel version?
The code will likely be run on Excel 2007 onwards, but I wont know which.
Or will I need to discover the xcel version and then select the correct pivottableversions
Thanks
Kris
PS I did post this on Microsoft Answers, but the answer was to ask on another forum!!