• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Refresh power query, wait till finished then save file?

Davealot

Member
Greetings,
Needing some perspective if possible. I have an excel spreadsheet that has powerqueries running in it from an Access Database. I'm trying to write a macro that will refresh all data, then once that is done to save the file.

So I started off with:

activeworkbook.refreshall
thisworkbook.save

That cancels the data refresh because it goes straight to saving the file. So I split it into two separate subs, and at the end of the refreshall sub I just called the save sub, still doesn't work. Is there a way to set it, where it doesn't lock the workbook where it's something like:

activeworkbook.refreshall

Wait ten seconds

thisworkbook.save

Not sure how to make this happen, any ideas are greatly appreciated!
 
Are all your query/connections set to .BackgroundQuery = False?

If not, setting it to False should resolve your issue (it forces code to wait for query to finish before doing other operations).
 
Are all your query/connections set to .BackgroundQuery = False?

If not, setting it to False should resolve your issue (it forces code to wait for query to finish before doing other operations).

TAADAAAA!!!! This is why I come to Chandoo! Thank you Chihiro!
 
OK let me ask a follow-up if possible. I have this replace an existing file doing a "Save As" with the notifications turned off so that it doesn't warn me that I'm replacing an existing file. The file that I'm using is "Workbook Group Leader" and the file that is being replaced is "PowerBI Slave". When I run the macro in Workbook Group Leader, it updates data, then saves, then replaces PowerBI slave via "Save as" and keeps the same name. But when the Save as happens, It closes Workbook Group Leader and I'm then sitting in PowerBI slave. Is there a way to have it...in essence just save the file, re-write PowerBI slave and stay in Workbook Group Leader?
 
Thanks for reply, I made change and am now getting error, I appreciate the help, any idea of what I can do? See attached
 

Attachments

  • Untitled.png
    Untitled.png
    22.5 KB · Views: 23
As shown in the link, only argument for ".SaveCopyAs" is file name (full path and file name). All other properties are taken from source workbook.
 
Back
Top