A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
assuming that source data is in Workbook1.xlsx, in Sheet1, in range A1:D100
and workbook1 path is in workbook2, in Sheet3, in cell A1
step1
Save As Workbook2 with extension .xlsm (macros enabled)
step2
in a regular module (in workbook2.xlsm) paste in the following macro:
Sub PT_ChangeSourceData()
For i = 1 To 2
Sheets(i).Activate
ActiveSheet.PivotTables(1).ChangePivotCache _
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
**Sheets("Sheet3").Range("A1").Value & "[Workbook1.xlsx]Sheet1!$A$1:$D$100",**Version:=xlPivotTableVersion14)
Next
End Sub
xxxxxxxxxxxxx
or
if your data source table is dynamic
try this code...
Sub Dynamic_ChangeSourceData()
'Mar 09, 2015
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Sheets("Sheet3").Range("A1").Value & "Workbook1.xlsx")
Dim rng
rng = wb.Sheets(1).Range("A1").CurrentRegion.Address
wb.Close False
For i = 1 To 2
Sheets(i).Activate
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
Sheets("Sheet3").Range("A1").Value & "[Workbook1.xlsx]Sheet1!" & rng, Version:=xlPivotTableVersion14)
Next
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub
note
path in Sheet3, in cell A1 is like
*c:\folder1\folder2*