VBA code to open an excel workbook, Refresh the query (PQ), once it has finished running, save and close the workbook

hananak

Board Regular
Joined
Feb 10, 2022
Messages
110
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Dear All,

I have a workbook (Transactions) in a folder which is connected to another source file using power query. The original source file has 200 columns, so the power query is used to do some transformation on the "Transactions file" to get rid of most of the columns and for other transformation. Currently, I have to manually open it every time to refresh and save it.

This Transactions file is connected to another file via Power Pivot using a data model relation via unique ID in the Power Pivot. This is done to take the benefit of of the Power Pivot feature "Drill Through". As the Transactions are huge in volume. I have searched a lot and to take advantage of the "Drill Through", the data has to be connected via OLAP - that's the only option.

I am looking for a VBA code, which I'll use in the file, which has the Power Pivot in it, on running the code, it should in the background open the "Transactions file", refresh the query, once it has finished running, save and close the file.
Then I will refresh the Power Pivot (Pivot table) and able to complete my various analysis.

I hope this makes sense.

Thanks for your help!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I would really appreciate if anyone can help!

Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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