Hi All,
I need help to solve a data Power Query refresh problem.
I coded the macro below to refresh 40 stock data sheets.
Sub AutoRefreshStockData()
Application.ScreenUpdating = False
Dim X As Integer
X = 0
For X = 5 To Worksheets.Count 'Set sheets to refresh
Sheets(X).Select ' Selects sheet to work with.
Range("A7").ListObject.QueryTable.Refresh BackgroundQuery:=False ' Refresh sheet
ProcessData ' Run data processing macro.
Next X ' Starts all over again
End Sub
When I first run the macro, I get the following error message:
Run-time error '1004':
Initialization of the data source failed.
Check the database server or contact your database administrator.
Make sure the external database is available, and then try the
operation again. If you see this message again, create a new data
source to connect to the database.
But I found that if I first manually refresh any one the 40 sheets , then the macro will run without error.
All suggestions and help will be appreciated.
Bookmarks