Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change source of a power query using VBA?

So in Excel 2016, they have this neat tool called Power Query, basically a glorified excel table. Every table has steps in it for filtering, removing columns, etc... The first step is the source step, to assign a connection string basically to retrieve data, normally this source just points back to the query which created it.

Anyways, I'm trying in VBA to dynamically change the source of these power queries, anyone have any ideas?

I tried using the whole connections vibe, but was unsuccessful.

like image 935
James Heffer Avatar asked Mar 18 '16 12:03

James Heffer


1 Answers

You can access the query through ActiveWorkbook.Item. You can then modify the Formula property. You can find the documentation on these objects here.

Please note that the Power Query object model was only added to VBA in Excel 2016 and cannot be accessed in prior versions.

like image 71
Alejandro Lopez-Lago - MSFT Avatar answered Sep 28 '22 06:09

Alejandro Lopez-Lago - MSFT