Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing PivotTable Source programmatically

I have several pivot tables in a workbook that get data from an Access .mdb
file.

But sometimes I need these pivot tables to obtain data from another Access
file.

Can I programmatically change the Source File of a Pivot Table, without
changing its query? Shall I use the PivotTableWizard? Or is there any
property that contains the Source File path?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Changing PivotTable Source programmatically

do you read the data using ADO ? If so, then the answer is easy - yes.

when you read the data into a recordset, all you need to do is set the pivot
cache's recordset property to this recordset and refresh the piviot table
To changethe source, all you need is alter the connection string.

do you need a code example?

Sub LoadDataFromAccess()
Dim MyFile As String
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String
Dim i As Long

MyFile = "Risk.mdb"

SQL = "SELECT * FROM BondTable"

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile

rst.Open SQL, con, adOpenStatic

Cells.Clear
'headers
For i = 0 To rst.Fields.Count - 1
Cells(1, i + 1).Value = rst.Fields(i).Name
Next
' data
Range("A2").CopyFromRecordset rs

rst.Close
con.Close

Set rst = Nothing
Set con = Nothing

End Sub





"Roberto Villa Real" wrote:

I have several pivot tables in a workbook that get data from an Access .mdb
file.

But sometimes I need these pivot tables to obtain data from another Access
file.

Can I programmatically change the Source File of a Pivot Table, without
changing its query? Shall I use the PivotTableWizard? Or is there any
property that contains the Source File path?

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
Programmatically getting a Max value from a PivotTable WhytheQ Excel Programming 1 October 25th 06 02:32 PM
Programmatically determine Chart's data source drussell Excel Programming 2 March 4th 06 05:25 AM
Programmatically reading data field values from PivotTable Enrico Campidoglio[_2_] Excel Programming 2 July 13th 05 12:32 PM
Excel VBA - How do I programmatically change source code in another file? Lisa Norgaard Excel Programming 1 July 14th 04 04:09 PM
Changing PivotTable source atakacs[_2_] Excel Programming 3 November 7th 03 03:35 AM


All times are GMT +1. The time now is 10:41 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"