I have a macro that copies a pivot table and its original source data in Workbook A to Workbook B. Is there a way to update the source data via Excel VBA that takes information from Workbook B ("fields") instead of Workbook A?
This is the code for identifying workbook B:
Dim WrkbookB As Workbook
Set WrkbookB = ActiveWorkbook
This is the code for importing the pivot table (in Sheet1) and original source data ("Fields") in Workbook A:
Dim WrkbookA As Workbook
folder = Application.GetOpenFilename("Excel.xlsx (*.xlsx), *.xlsx," & _
"Excel.xls (*xls), *xls", 1, "Select Workbook A")
Set WrkbookA= Workbooks.Open(Filename:=folder)
WrkbookA.Sheets("Sheet1").Copy After:=WrkbookB.Sheets(1)
ActiveSheet.Name = "Sheet1"
WrkbookA.Sheets("Fields").Copy After:=WrkbookB.Sheets(1)
WrkbookA.Close SaveChanges:=False
Any help on how to change the data source is greatly appreciated.
Active
properties and stick to either specifying workbooks by name and worksheets by name or index number – Marcucciboy2