Vba code to wait until query & calculations are complete before proceeding

BennyBB

New Member
Joined
Sep 6, 2013
Messages
33
I am looking for VBA code sample for the following situation....


My excel code currently does a REFRESH ALL DATA. At which point in the lower left is displayed the message, "RUNNING BACKGROUND QUERY ... (CLICK HERE TO CANCEL)". Also later at times when I refresh, I get a message, "CALCULATING: (4 PROCESSOR(S)): ##%"....

Is there a was in VBA to have my code pause until these messages disappear? These messages go away on there own with time & patients.

I want a closed loop solution and don't want to input a pause unless there is a way to check TRUE/FALSE if either message is displayed (is preferred).


Thanks,


BennyB

P.S. Win7 64, Office 2013 32bit.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

CalcSux78

Well-known Member
Joined
Oct 15, 2013
Messages
1,120
With RefreshAll, your code is most likely resuming the next lines before all connections are refreshed.

Instead, try refreshing each connection (one by one). The code should wait until refresh is completed before resuming the next line. If you have multiple connections, you could loop through all connections with something to this effect:

Code:
Dim Conn As WorkbookConnection

For Each Conn In ThisWorkbook.Connections
    Conn.Refresh
Next Conn
 

sandev

New Member
Joined
Sep 30, 2020
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
  3. Web
I confirm this solution of @CalcSux78 did not work on my Windows 10, Excel 2019 64 bit. The connection is a Query to get data from a CSV file.

I will solve my problem with some checks if length of the A2 Value is bigger than 0. Probably I will need to be deleting the tables in order to do that check.
VBA Code:
Do Until Len(ActiveSheet.Range("A2").Value) > 0
    Application.Wait (Now + TimeValue("0:00:2"))
Loop
 

Watch MrExcel Video

Forum statistics

Threads
1,129,476
Messages
5,636,556
Members
416,923
Latest member
jarri

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
Top