简体   繁体   English

Excel宏 - 测试是否已安装Excel Addin的Power Query

[英]Excel Macro - Test if Power Query for Excel Addin in installed

Is it possible to test if "Power Query for Excel" add-in is installed and enable using excel macros ? 是否可以测试是否安装了“Power Query for Excel”加载项并使用excel宏启用? I'd like to use it to authorize the Data refreshing of my workbook which is connected to several data sources using this add-in. 我想使用它来授权我的工作簿的数据刷新,该工作簿使用此加载项连接到多个数据源。

Thanks and Regards. 谢谢并恭祝安康。

You could use something like this, as it's a COM add-in: 你可以使用这样的东西,因为它是一个COM加载项:

Function IsPowerQueryAvailable() As Boolean
    Dim bAvailable As Boolean
    On Error Resume Next
    bAvailable = Application.COMAddIns("Microsoft.Mashup.Client.Excel").Connect
    On Error GoTo 0
    IsPowerQueryAvailable = bAvailable
End Function

If you actually wanted to try and enable it as well if it is present, you could use something like this: 如果你真的想尝试启用它,如果它存在,你可以使用这样的东西:

Function IsPowerQueryConnected() As Boolean
    Dim bAvailable      As Boolean
    Dim oPQ             As COMAddIn
    On Error Resume Next
    Set oPQ = Application.COMAddIns("Microsoft.Mashup.Client.Excel")
    If Not oPQ Is Nothing Then
        If Not oPQ.Connect Then oPQ.Connect = True
        bAvailable = oPQ.Connect
    End If
    IsPowerQueryConnected = bAvailable
End Function

You can check if addin is installed by: 您可以通过以下方式检查是否安装了插件:

AddIns("AddInName").Installed

ie: 即:

Sub Foo()
If AddIns("AddIn name").Installed Then
  'installed
Else
  'not installed
End If
End Sub 

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

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