Msgbox displays before the query has finished refreshing

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I often have this rather annoying issue where at the end of a sub I have a message box to let me know when the query refresh is done. The same also applies for an external program I run.

More often than not, the MsgBox gets displayed ahead of the query or external program finishing.

I have tried all manner of methods to avoid this as there are many suggestions on the Interne.

Does anybody have tried and tested method to display the message box AFTER the query has finished refreshing.

As always, thanks in advance.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
VBA Code:
Sub Optimise(Flag As Boolean)
On Error Resume Next
F = Not Flag
Application.ScreenUpdating = F
Application.DisplayAlerts = F
Application.EnableEvents = F
Application.DisplayStatusBar = F
ActiveSheet.DisplayPageBreaks = F
If F = True Then
Application.Calculation = xlCalculationAutomatic
Else
Application.Calculation = xlCalculationManual
End If
On Error GoTo 0
End Sub
Sub Update()
'switch off updating to stop screen flickering
Optimise (True)
SheetList = Array("Sheet1", "Sheet2", "Sheet3")
For Count = 0 To UBound(SheetList)
ActiveWorkbook.RefreshAll
DoEvents

,Rest of your code


'allow screen to update now
Optimise (False)
'reprotect the modified sheets
For Count = 0 To UBound(SheetList)
DoEvents
'Sheets(SheetList(Count)).Protect
Next
MsgBox "Job Done"
End Sub
 
Upvote 0
Thanks Kerry.

However, I finally solved the issue by going int the properties of the Query itself and disabling the Background Refresh option.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,133
Messages
6,123,233
Members
449,092
Latest member
SCleaveland

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