Originally Posted by Sir Humphrey Appleby
I'm trying to write a macro which will fill in tables for me at a certain hour, I can get a web query, refresh it and copy the data into a cell but if I do that it won't wait for the query to finish downloading. Is there a way to delay it until the previous action is finished?
So is the web query embedded in the spreadsheet? If so, I wouldn't think that the macro would proceed until the query refresh has been completed, but this may not be the case for you.
I can think of two possible solutions. First, you could tell the macro to wait for a specified period of time, which should give the query enough time to finish before carrying out the remainder of the code in the macro. Here is an example I found for how to write in a waiting period:
Use this code for waiting 5 seconds
' Waits 5 seconds
Application.Wait Time + TimeSerial(0, 0, 5)
' Continues here after pause
Second, say you know that the query will finish at 6:30 a.m. every day. You could set up a "Scheduled Task" in Windows that would open up the file, the file could run the macro upon opening. The Scheduled Task could be set up to run a some specified time that would be well after you know the query will have been competed each day. Here is a link
that talks about how to set up a Scheduled Task.