Refresh All and then Message stating Complete

johnny51981

Active Member
Joined
Jun 8, 2015
Messages
366
Hi Again!
What is the best way to use the ActiveWorkbook.RefreshAll VBA and then provide a Message Box stating that the RefreshAll is complete?

I have had my queries refresh in a particular order, only because I am in need of a message of its completion, there is really no other reason for me to do this and I would like to increase its refresh speed (turning the Background Refresh back on).

I've tried adding DoEvents in the VBA line following the RefreshAll, but it still tries to bring up the message box before all queries are complete.

Any thoughts?
Here is a sample code of what I am currently using. Thank you in advance!

VBA Code:
Sub RefreshData()

    Dim answer1 As Integer
    answer1 = MsgBox("Would you like to refresh all the Data?", vbQuestion + vbYesNo + vbDefaultButton2, "Refresh All Data")
    If answer1 = vbYes Then
    
'    ActiveWorkbook.Connections("Query - Query Seq 1").Refresh
'    ActiveWorkbook.Connections("Query - Query Seq 2").Refresh
'    ActiveWorkbook.Connections("Query - Query Seq 3").Refresh
'    ActiveWorkbook.Connections("Query - Query Seq 4").Refresh
'    ActiveWorkbook.Connections("Query - Query Seq 5").Refresh
'    ActiveWorkbook.Connections("Query - Query Seq 6").Refresh
    
    ActiveWorkbook.RefreshAll
    DoEvents
        
    Call VarianceCheck
    
    answer1 = MsgBox("Data Refresh Successfull!", vbOKOnly)
    Else: answer1 = MsgBox("Data Refresh Cancelled!", vbOKOnly)
    End
    End If
End Sub

VBA Code:
Sub VarianceCheck()
    
    myMetric = Range("Variance")
    If myMetric = "YES" Then
    
    answer1 = MsgBox("There is a Variance in the report's data.", vbOKOnly)
    End
    
    Else: ActiveWorkbook.Save
    
    End If
    
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Very difficult. Refresh all operates as a background query. You may be able to change that with code - I’m not sure. If you refresh one of the tables, you can definitely turn off background query with an optional parameter. I don’t know the syntax
 
Upvote 0

Forum statistics

Threads
1,215,232
Messages
6,123,763
Members
449,120
Latest member
Aa2

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