excelvbaexcel-web-query

How to handle a Time Out?


I am running an Excel power query in a loop. The query runs.

For a reason related to the internet (I am not in a fiber covered area) the query fails to load the data, returning a time out error.

enter image description here

Given that is possible the entire loop cycle has not completed, I would like to stop the refresh before the error pops up and resume with the code despite no data having been loaded.

The code breaks where it is shown in the pic.

How can I have the code keep running before the time out will appear?

enter image description here

Let's say I would like the code to keep executing if after 90 seconds the data cannot be loaded.


Solution

  • Why don't you try to change the refresh period?

    You can also try to look at the code generated by Power Query by Unchecking the "Enable Background Refresh" in the Data -> Connection -> Properties.

    You can also add a timeout of your choice. You can add this bit after you defined the URL

    , [Timeout = #duration (X,Y,Z,N)]
    

    Where X is Days, Y is Hours, Z is Minutes, N is Seconds

    Else if you are really interested on killing the Web Query after the default 100 seconds, then before starting the code you can put this line

    On Error Resume Next