Share via

VBA MsgBox After Background Query Completion

Anonymous
2022-08-04T11:38:35+00:00

I have created a VBA code to import data from CSV convert it into a table and refresh the query that is already setup.

I want the user to be informed when the background query is completed by displaying a VBA msgbox.

I tried below code but it doesn't work because if condition would be nothing by the the time query is completed. So no msgbox will be display.

Do I need to setup some delay like 15 sec and display msgbox anyway but then it wouldn't be a good idea.

How to sync background query completion with VBA msgbox?

ThisWorkbook.RefreshAll 

Sheets(2).Select 

If Sheets(2).Range("AG3").Value <> "" Then MsgBox "Completed"
Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-08-07T12:47:41+00:00

    Thank you for the suggestion. I posted it on Stack Overflow as you suggested and got an answer.

    I have pasted the solution below, incase anyone would like to use it. It works flawless.

    With ThisWorkbook

        For Each objConnection In .Connections 
    
            'Get current background-refresh value 
    
            bBackground = objConnection.OLEDBConnection.BackgroundQuery 
    
            'Temporarily disable background-refresh 
    
            objConnection.OLEDBConnection.BackgroundQuery = False 
    
            'Refresh this connection 
    
            objConnection.Refresh 
    
            'Set background-refresh value back to original value 
    
            objConnection.OLEDBConnection.BackgroundQuery = bBackground 
    
        Next 
    
        'Save the updated Data 
    
        .Save 
    

    End With

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2022-08-05T14:28:13+00:00

    Dear ExcelFunTension,

    Good day! Thank you for posting to Microsoft Community. We are happy to help you.

    As per your description, it seems that you want to sync background query with VBA msgbox.

    We would love to help you on your query about VBA code, however, our team focuses on general query, for example, installation and activation issue of Office 365 products. The situation you mentioned is related to VBA code, you can refer to this article: Office VBA support and feedback | Microsoft Docs to go to Stack Overflow by using the VBA tag, along with any other relevant tags as there are also many experienced engineers and experts in the forums there.

    Disclaimer: Microsoft provides no assurances and/or warranties, implied or otherwise, and is not responsible for the information you receive from the third-party linked sites, or any support related to technology.

    At the same time, we will also keep this thread open, so other Community members and Experts can also share their suggestions and inputs.

    Your understanding and patience will be highly appreciated. I hope that you are keeping safe and well!

    Sincerely,

    Waqas Muhammad

    ***Note: In the event that you're unable to reply to this thread, please ensure that your Email address is verified in the Community Website by clicking on Your Account Name > "My Profile" > "Edit Profile" > Add your Email Address > tick "Receive email notifications" checkbox > click on "Save".***

    Was this answer helpful?

    0 comments No comments