简体   繁体   中英

Can I set the username and password for an Excel Power Query via vba?

I'm trying to set up a spreadsheet to be used by others that updates tables via Power Query. When another user uses the spreadsheet they are asked 3 times to enter their username and password because I have 3 tables being updated. How can I set these for each user via VBA?

I tried setting the connections to anonymous, but they couldn't access the data. I already ask the user their password and could use it. I tried seeing how to set it by doing it as I recorded a macro, but the information was not recorded. I looked at the objects to see if the listobject or the querytable has a password setting. There is a save password but it is a property. It doesn't look like I can set it.

There is no way to pass credentials to a Power Query with VBA. This would be in violation of the security model around Power Query. Every user that wants to refresh a query needs to have their own access to the data source. Credentials are not stored with the workbook or in the query. Instead the credentials are set with the connections, which are independent of particular workbooks and stored on the local machine.

In your situation, you need to give all people access to the data sources contained in the workbook.

As an alternative, you can set up a workbook with all the queries, load the data into the grid and refresh the data as required, using your credentials. Then you can build another workbook that reads the data from that file. Give the report consumers access to that workbook, then they don't need access to the original data sources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM