How to Determine if the Refresh of a Workbook Query has Failed

89 Views Asked by At

Is there a way to programmatically determine (through VBA code) whether or not the Refresh of an embedded query in a Workbook has failed? I've had a look at the properties of the Excel WorkbookConnection object, and there doesn't appear to be any property that tells me the status of the Refresh operation, successful or otherwise.

I can see in the Workbook itself if the refresh was successful or not, as shown in the attached image, but there doesn't seem to be a way to access this information through the Excel object model.

I can put an error handler immediately before invoking the .Refresh method to trap an error if one occurs, and give the user the option as to whether or not to continue, but ideally I'd prefer to attempt all the Refresh operations first (there are multiple data connections in the workbook) and then advise the user of how many queries were successful, and for those that weren't successful, list the ones that failed. I then want to give the user the option to proceed or cancel based on the information provided.

Image of an error dialog box for an Excel data query

0

There are 0 best solutions below