Excel VBA Refresh Wait

ployo60

New Member
Joined
Jan 22, 2012
Messages
2
I am trying to create a button with a macro code. When the button is pressed it will run a refresh code for a webpage. One of the sheets is updated with the information from this website. There is a waiting period for the refreshing. When done refreshing the rest of the code is run. My problem is the waiting part. Depending on my location and internet speed it sometimes takes 2 seconds to load and sometimes 8 seconds. I want create a timer that will look at when excel is refreshing, wait till its done and then run the rest of the code. See below for a small exable.

Simple code:

Code:
ActiveWorkbook.RefreshAll

Here I need the delay or waiting code till all the refreshing is finished... Then

Code:
MsgBox("The Refreshing is Completed!")



Hope anyone can help!!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi

It would be easier to simply disable backgrund refresh of the query (if you do this, when you trigger the refresh, your code will wait until the refresh has completed before executing the subsequent lines). Do this via selecting one of the cells in your external data range and in 2007+ hit the Properties button on the Data ribbon (or in 2003 right-click the mouse and select Properties - I think, can't quite remember).

Now, uncheck the box for Enable Background Refresh. Save the workbook to fix the property. Then you can simply have your subsequent code immediately following the RefreshAll line.
 
Upvote 0
Perfect indeed! I have been trying for months to figure out how to do this. I had two files that had to be refreshed - one worked and the other didn't. I couldn't work out why, or what to do. This solved it for me. That box was checked in the one that didn't work, and not in the one that did.
I registered with this forum just so I could say thank you to Firefly2012.
Thank you FireFly2012!!!
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top