Excel Macro - Test if Power Query for Excel Addin

2019-08-09 15:02发布

Is it possible to test if "Power Query for Excel" add-in is installed and enable using excel macros ? 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.

2条回答
爷、活的狠高调
2楼-- · 2019-08-09 15:29

You could use something like this, as it's a COM add-in:

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
查看更多
叛逆
3楼-- · 2019-08-09 15:29

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 
查看更多
登录 后发表回答