This example displays a message box if there’s a background query in progress for query table one.
With Worksheets(1).QueryTables(1)
If .Refreshing Then
MsgBox "Query is currently refreshing: please wait"
Else
.Refresh BackgroundQuery := False
.ResultRange.Select
End If
End With