Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default query source code

I needed to redirect my pivot table worksheets to a
database in another location. I tried the code suggested
by the newsgroup and was successful. However, all of the
pivot tables have underlying queries. The source path is
located in every one of those queries. In order to
refresh my data from the new location, I had to "get data"
to open the query, click on SQL, and modify the SQL
statement to change the path (for each pivot table!). In
this situation, there were only 10 or so pivot tables.

However, I have another workbook that has many, many pivot
tables. It would be insane to change each one this way.
What code can I use to change the path in all of the
underlying queries? Note that each query is not saved, it
is buried somewhere behind each pivot table. I know there
is a way to do this.

For your info, here is the code I used to change the
source of the mdb:

Public Sub ResetPivotTableConnection()
Dim pc As PivotCache
Dim pt As PivotTable
Dim str As String
Set pt = Sheet2.PivotTables("PivotTable2")
Set pc = ThisWorkbook.PivotCaches(pt.CacheIndex)
'Debug.Print pc.Connection
str = "ODBC;DSN=MS Access Database;"
str = str
& "ODBC;DBQ=c:\....Summ_Data.mdb;DefaultDir=c:\....; Driver=
{Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS
Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeou t=5;SafeT
ransactions=0;Threads=3;UID=admin;UserCommitSync=Y es;"
pc.Connection = str
End Sub


Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default query source code

Mel

Something like this

Sub ChangeSQL()

Dim OldPath as String
Dim NewPath as String
Dim sh as Worksheet
Dim pt as PivotTable

OldPath = "C:\MyOldPath"
NewPath = "C:\MyNewPath"

For Each sh in ThisWorkbook.Worksheets
For Each pt in sh.PivotTables
pt.PivotCache.CommandText = Replace( _
pt.PivotCache.CommandText,OldPath, _
NewPath)
Next pt
Next sh

End Sub

If you have pivot tables that are not external data, then you may have to
check for that. Try this out and let me know if it needs modification.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Mel" wrote in message
...
I needed to redirect my pivot table worksheets to a
database in another location. I tried the code suggested
by the newsgroup and was successful. However, all of the
pivot tables have underlying queries. The source path is
located in every one of those queries. In order to
refresh my data from the new location, I had to "get data"
to open the query, click on SQL, and modify the SQL
statement to change the path (for each pivot table!). In
this situation, there were only 10 or so pivot tables.

However, I have another workbook that has many, many pivot
tables. It would be insane to change each one this way.
What code can I use to change the path in all of the
underlying queries? Note that each query is not saved, it
is buried somewhere behind each pivot table. I know there
is a way to do this.

For your info, here is the code I used to change the
source of the mdb:

Public Sub ResetPivotTableConnection()
Dim pc As PivotCache
Dim pt As PivotTable
Dim str As String
Set pt = Sheet2.PivotTables("PivotTable2")
Set pc = ThisWorkbook.PivotCaches(pt.CacheIndex)
'Debug.Print pc.Connection
str = "ODBC;DSN=MS Access Database;"
str = str
& "ODBC;DBQ=c:\....Summ_Data.mdb;DefaultDir=c:\....; Driver=
{Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS
Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeou t=5;SafeT
ransactions=0;Threads=3;UID=admin;UserCommitSync=Y es;"
pc.Connection = str
End Sub


Thanks in advance.



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
Change data source for MS Query TonyL Excel Discussion (Misc queries) 2 September 11th 08 10:44 PM
Data Source for MS Query Suzseb Excel Discussion (Misc queries) 0 May 24th 06 08:09 PM
changing query source [email protected] Excel Worksheet Functions 2 March 21st 06 08:55 PM
How to find a query source TonyL Excel Worksheet Functions 1 March 5th 06 06:24 AM
Changing Query Source Location? Jennifer Crawford Excel Programming 7 August 12th 03 07:43 PM


All times are GMT +1. The time now is 12:40 AM.

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"