Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Pivot cache when pivot table copied

Hello,

I have a worksheet that contains a pivot table which uses an external data
source (SQL). I've written a script to update the SQL statement in the pivot
cache so the user can simply change some query criteria on the worksheet and
update the pivot table (specifically, the user can enter a name in a cell and
the pivot table displays work data pulled from MS Project server). I would
like the user to be able to copy the worksheet, change the name and update
the pivot table (ex.: so he can create one worksheet per team member). When
I make a copuy of the worksheet the script doesn't work. I've found that the
pivot table initialy has the same pivot cache as the original (same cache
index). The only way I have found to get a new pivot cache is to manualy go
and change the data source for the pivot table...this creates a new pivot
cache and the script works fine after that. Is there anyway to do this
programatically?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Pivot cache when pivot table copied

Ok...found this workaround:

Dim ptProjects As PivotTable
Dim NewPC As PivotCache
Dim NewPT As PivotTable

'*** Get a refrence to the current pivot table on the new worksheet
Set ptProjects = ActiveSheet.PivotTables("ResProjects")

'*** Create temporary pivot table with new pivot cache in out of the way
location
Set NewPC = ActiveWorkbook.PivotCaches.Add(xlExternal)
NewPC.Connection = "ODBC connection string goes here"
NewPC.CommandText = "SQL statements"
NewPC.CommandType = xlCmdSql
Set NewPT = NewPC.CreatePivotTable(Range("Z1"), "Temp")
NewPC.Refresh

'*** Link current pivot table to new pivot cache associated to temp pivot
table
ptProjects.CacheIndex = NewPT.CacheIndex

'*** Delete temporary pivot table
Columns("Z:AD").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select


"Michael Glenn" wrote:

Hello,

I have a worksheet that contains a pivot table which uses an external data
source (SQL). I've written a script to update the SQL statement in the pivot
cache so the user can simply change some query criteria on the worksheet and
update the pivot table (specifically, the user can enter a name in a cell and
the pivot table displays work data pulled from MS Project server). I would
like the user to be able to copy the worksheet, change the name and update
the pivot table (ex.: so he can create one worksheet per team member). When
I make a copuy of the worksheet the script doesn't work. I've found that the
pivot table initialy has the same pivot cache as the original (same cache
index). The only way I have found to get a new pivot cache is to manualy go
and change the data source for the pivot table...this creates a new pivot
cache and the script works fine after that. Is there anyway to do this
programatically?

Thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table (column/row) label cache reset Kris Excel Discussion (Misc queries) 4 December 31st 12 09:07 AM
How to Clear a Pivot Table Cache DoctorG Excel Discussion (Misc queries) 1 February 16th 10 03:04 PM
Excel Pivot Table cache bonxie Excel Discussion (Misc queries) 2 June 8th 07 05:45 PM
multiple pivot tables from 1 pivot cache sugargenius Excel Programming 0 February 22nd 07 07:41 PM
Can't set CommandText if pivot table copied steveh Excel Programming 2 January 27th 07 03:23 PM


All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"