Forum Discussion

PowerBI_Query's avatar
PowerBI_Query
Helper II
4 years ago
Solved

Background Query Completion

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 displa...
  • PowerBI_Query's avatar
    4 years ago

    Posted the question on VBA forum and got the below solution 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
    MsgBox "Completed"