Hello,
I have 6 Excels files. I am using one file as the main file, and the other five I am using as data connections for the main file. My code is as follows
Sub DataRefresh()
Dim wkb as Workbook
Set wkb = Workbooks.Open("filepath")
wkb.RefreshAll (This is where the debugger says the error is)
wkb.Close SaveChanges:=True
*Repeat with different names for other files*
ThisWorkbook.RefreshAll
End Sub
Any ideas?
EDIT
Here's the full code:
I have 6 Excels files. I am using one file as the main file, and the other five I am using as data connections for the main file. My code is as follows
Sub DataRefresh()
Dim wkb as Workbook
Set wkb = Workbooks.Open("filepath")
wkb.RefreshAll (This is where the debugger says the error is)
wkb.Close SaveChanges:=True
*Repeat with different names for other files*
ThisWorkbook.RefreshAll
End Sub
Any ideas?
EDIT
Here's the full code:
Code:
Sub DataRefreshTest()
'Declaration - declare an object for setting the workbook
Dim wkb As Workbook
Dim wkb1 As Workbook
Dim wkb2 As Workbook
Dim wkb3 As Workbook
Dim wkb4 As Workbook
'Open Workbook and set an object(wkb)
Set wkb1 = Workbooks.Open("C:\Users\nb954s\Documents\Exchange_Rate_Data_A_C")
wkb1.RefreshAll
wkb1.Close SaveChanges:=True
Set wkb2 = Workbooks.Open("C:\Users\nb954s\Documents\Exchange_Rate_Data_D_K")
wkb2.RefreshAll
wkb2.Close SaveChanges:=True
Set wkb3 = Workbooks.Open("C:\Users\nb954s\Documents\Exchange_Rate_Data_L_R")
wkb3.RefreshAll
wkb3.Close SaveChanges:=True
Set wkb4 = Workbooks.Open("C:\Users\nb954s\Documents\Exchange_Rate_Data_S_Z")
wkb4.RefreshAll
wkb4.Close SaveChanges:=True
Set wkb = Workbooks.Open("C:\Users\nb954s\Documents\Exchange_Rate_Summary")
wkb.RefreshAll
wkb.Close SaveChanges:=True
ThisWorkbook.RefreshAll
MsgBox "Data Refresh complete. All values have been updated. Click 'OK' to continue"
End Sub
Last edited by a moderator: