Move on to next step in VBA code if power query does not refresh or gets hung up

MGTexas123

New Member
Joined
Jan 1, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
If I run a VBA Macro in Excel that instructs a number of power queries in the workbook to refresh, how do I get the VBA code to move to the next step if a query refresh gets stuck (e.g. does not load)? Here is an example of the VBA code:

Sub New_Requests()


ActiveWorkbook.Connections("Query - New Requests").Refresh
ActiveWorkbook.Connections("Query - New Requests Export File to ACT").Refresh


End Sub





Thanks in advance for any help on this!

Matt
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If I run a VBA Macro in Excel that instructs a number of power queries in the workbook to refresh, how do I get the VBA code to move to the next step if a query refresh gets stuck (e.g. does not load)? Here is an example of the VBA code:

Sub New_Requests()


ActiveWorkbook.Connections("Query - New Requests").Refresh
ActiveWorkbook.Connections("Query - New Requests Export File to ACT").Refresh


End Sub





Thanks in advance for any help on this!

Matt

Hi Matt
It depends on how you determine whether your queries are getting stuck. You could enable background refreshing on your queries and then wait for some period of time, but I don't think there is really a good way of cancelling the refresh in VBA. You might be better trying to identify what's causing the problem with the queries themselves in my opinion. Though someone else might have a better suggestion than me of course.
 
Upvote 0
Hi Matt
It depends on how you determine whether your queries are getting stuck. You could enable background refreshing on your queries and then wait for some period of time, but I don't think there is really a good way of cancelling the refresh in VBA. You might be better trying to identify what's causing the problem with the queries themselves in my opinion. Though someone else might have a better suggestion than me of course.
Thanks for your help with this and the suggestion. I've tried this in the past, but no luck. The main issue is that when Power Query pulls data from an external source such as Sharepoint folder or Google sheets, about 1 out of 5 times the query simply will not refresh and get stuck. What I can't figure out is what is causing the query to hang up some of the time, but not all of the time. The only workaround I can think of is to add to the VBA code (when we run the queries in a Macro) the ability to skip queries that are getting hung up in the macro. Any additional suggestions on how to either solve the core problem, or what VBA code to include in the macro would be greatly appreciated.
 
Upvote 0
Thanks for your help with this and the suggestion. I've tried this in the past, but no luck. The main issue is that when Power Query pulls data from an external source such as Sharepoint folder or Google sheets, about 1 out of 5 times the query simply will not refresh and get stuck. What I can't figure out is what is causing the query to hang up some of the time, but not all of the time. The only workaround I can think of is to add to the VBA code (when we run the queries in a Macro) the ability to skip queries that are getting hung up in the macro. Any additional suggestions on how to either solve the core problem, or what VBA code to include in the macro would be greatly appreciated.
I would put the power query problem up as a separate post first, as that should speed up any solutions for that.
Have you tried just leaving the query running for as long as possible when it's getting stuck?
 
Upvote 0
JB2020,

Thanks for your question. I have let the query run for several minutes and Excel eventually throws a VBA error some of the time. I've tried to break the query down into smaller steps, but no luck. What makes this challenging, is the problem only occurs about 1 out of 5 times when I run the macro.

Matt
 
Upvote 0
JB2020,

Thanks for your question. I have let the query run for several minutes and Excel eventually throws a VBA error some of the time. I've tried to break the query down into smaller steps, but no luck. What makes this challenging, is the problem only occurs about 1 out of 5 times when I run the macro.

Matt

Hi Matt

Have you had any more luck with this? I would suggest trying to run the query outside of VBA and leaving it running when it gets stuck, at least then if it throws out an error you will be able to see what's causing it, or whether it is just taking ages to refresh sometimes for whatever reason.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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