简体   繁体   English

我可以通过vba设置Excel Power Query的用户名和密码吗?

[英]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. 我正在尝试建立一个供其他人使用的电子表格,以通过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. 当另一个用户使用电子表格时,由于我有3个表正在更新,因此要求他们3次输入用户名和密码。 How can I set these for each user via VBA? 如何通过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. 我查看了对象,以查看listobject或querytable是否具有密码设置。 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. 无法通过VBA将凭据传递给Power Query。 This would be in violation of the security model around Power Query. 这将违反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. 向报表使用者提供对该工作簿的访问权限,那么他们就不需要访问原始数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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