简体   繁体   中英

Excel VBA: How to show connected query Load status in a pop-up/ alert message?

I am having a problem with my Excel spreadsheet. I have a Query linked to the spreadsheet. I want the users can refresh the query and run a macro code once they click on a Refresh button. Pretty simple demand, The problem is sometimes some users do not have the access to the source data. so the query does not update properly. But When they click on the refresh button it does not show any error message to them and continue to run the macro code without updating the query? Is there any good process to show them the status that the query did not download the data, ** This is my first post on this site. I apologize if I have not followed the question format properly. thank you all. This site is really helpful for me always.

for error control you can use this:

Public Function example()
On Error GoTo Err_Control

' you code

Err_Control:
    If Err.Number <> 0 Then
        If Err.Number = 1004 Then
            MsgBox "You do not have permission to access the data source." & Chr(13) & "Macro will be finished."
            Exit Function
        Else
            MsgBox Err.Number & " - " & Err.Description
        End If
    End If
End Function

Iinside Err_Control you put the error handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM