VBA to refresh multiple background queries, then wait for completion

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a file with 2 sets of queries (2 queries per set for a total of 4 queries), where the first 2 queries must be refreshed first, then the next 2 refreshed after that. They are Power Query queries where the second 2 use the data from the first 2.

If I do this manually, I right-click and refresh the first two, wait for those to finish, then refresh the next 2 queries.

I'd like to automate this with VBA but what I would really like to do is refresh the first 2 queries and allow background refresh to take place, but then wait until they are complete before proceeding. The only way I know how to do this with VBA is the following

VBA Code:
Sheet1.ListObjects(1).QueryTable.Refresh BackgroundQuery:=False

This works, but then it means query #1 must refresh, then #2, but I would really prefer to have background refresh enabled to allow both to refresh at the same time (they take a few minutes each, so it's nice to allow them to work at the same time).

Is there any way to refresh a grouping of queries with background refresh enabled, then wait for that to finish before proceeding?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
An untested idea. Use a simple loop

do while SheetA.ListObjects(1).refreshing or SheetRef.ListObjects(2).refreshing
loop

If this causes problems, first thought is to put a doevents in the loop
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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