long time reader, first time asker,
I have a master file that when i hit a button will Open 11 files one by one refresh the connections and close the files. however, it's not refreshing the connections before it closes the file.
Sub Task()
Workbooks.Open Filename:= "......sharepoint.com/sites/dummylocation/dummyfile.xlsx"
Dim WB As Workbook
Set WB = Application.Workbooks("dummy file.xlsx")
Dim ObjConnection As Variant
Dim bBackground As Variant
For Each ObjConnection In WB.Connections
'Get current background-refresh value
bBackground = ObjConnection.OLEDBConnection.BackgroundQuery
'Temporarily disable background-refresh
ObjConnection.OLEDBConnection.BackgroundQuery = False
'Refresh this connection
ObjConnection.Refresh
'Set background-refresh value back to original value
ObjConnection.OLEDBConnection.BackgroundQuery = bBackground
Next
WB.Close
End Sub
Ive been able to fault find it a little bit by commenting out the "wb.cose" which the Refresh then works. Im assuming i need some kind of delay or something?????