Results 1 to 3 of 3

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

  1. #1
    Neophyte jdorbish's Avatar
    Join Date
    Jan 2019
    Posts
    4
    Articles
    0
    Excel Version
    Professional Plus 2016

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



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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 (picture of error attached). Is there vba code I can add that will alert me if the query doesn't finish successfully? Thanks!

    Click image for larger version. 

Name:	Error.PNG 
Views:	13 
Size:	68.5 KB 
ID:	8768


    Code:
    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

  2. #2
    Administrator AliGW's Avatar
    Join Date
    Nov 2015
    Location
    Ipswich, Suffolk, England
    Posts
    1,251
    Articles
    0
    Excel Version
    Office 365 Subscription
    One thread per issue only, please. I have closed your other thread. Thanks.
    Ali
    Enthusiastic self-taught user of MS Excel!

  3. #3
    Neophyte jdorbish's Avatar
    Join Date
    Jan 2019
    Posts
    4
    Articles
    0
    Excel Version
    Professional Plus 2016
    Bump! Can anyone help?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •