Refreshing Queries using VBA - Message Alert for Queries that Failed to Refresh

jdorby

New Member
Joined
Jul 28, 2014
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the below code that refreshes a workbook that uses a power query data model as it's source. My issues is that, even when the queries fail (if another person has one of the source workbooks open, the file path is wrong for one of the query connections, I have a many to one relationship in my dimensions table, etc.), the vba code finishes and acts as if the query refreshed successfully. It's not until I run the query manually that I receive a popup showing the query produced an error that I'm aware the query didn't run successfully. Is there vba code I can add that will alert me if the query doesn't finish successfully? Thanks!

Code:
[/COLOR]Dim Connection As WorkbookConnection

    For Each Connection In ThisWorkbook.Connections
        Connection.Refresh
    Next Connection
    Dim qt As QueryTable
For Each wks In ActiveWorkbook.Worksheets
For Each qt In wks.QueryTables
qt.Refresh
Next qt
Next wks
    
    

    ActiveWorkbook.RefreshAll[COLOR=#333333]
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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