VBA to Open Power Query and set folder to append .csv files

Brass Contributor

I would like to automate some functions in Power Query using VBA because users most likely will not know how to use Power Query to do the following. I already have some code where a user selects a folder path to some files. The code does more than this of course but utilizing the fact that the user has already selected the folder location, I want to use that data source toward the end of the process to open up Power Query. Then, do the equivalent of Selecting get data, Get Folder (this would be already declared). Where it would retrieve several .csv files. Now this may not be do-able but I would also like to utilize what functions I write in Power Query after those files have merged and run those set of instructions on the files before Closing & Loading into the Workbook.

2 Replies
I don't understand the problem. Users should not have to open PowerQuery as long as you have set up that query properly, all they have to do is refresh the query?

@Jan Karel Pieterse Sorry, I did not mention that this process would be used as a first time setup for other users. Not every user knows how to use Get & Transform (Power Query sounds so much better), so, it would just be something to initially gather the data and set the PQ up. I did find some information here https://excelunplugged.com/2018/01/23/modifying-power-query-m-code-with-vba/ that I have not tried yet but hope it will work for what I am doing. I will follow up and update here if it does or does not work.