Question : EXCEL 2007 VBA Dynamically changing the external datasource of a pivot table

Hi

I would like to know whether we can dynamically change the datasource of a pivot table.

The requirement is as follows

A cell(say A5) will contain the fullpath and file name of the external datasource. When we change the value of this cell(A5)(ie a different path and filename), datasource should point to the new file.

Normally to change the datasource, we need to select the "change datasource" from options menu and then refresh it.

Thanks

Answer : EXCEL 2007 VBA Dynamically changing the external datasource of a pivot table

Try the code below, you'll need to change the pivot table name
1:
2:
3:
Sub ChangeDataSource()
ActiveSheet.PivotTables("PivotTable1").ChangeConnection ActiveWorkbook.Connections(Range("B5").Value)
End Sub
Random Solutions  
 
programming4us programming4us