Excel Macro - Test if Power Query for Excel Addin in installed

坚强是说给别人听的谎言 提交于 2020-01-05 09:08:44

问题


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.


回答1:


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



回答2:


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 


来源:https://stackoverflow.com/questions/24201107/excel-macro-test-if-power-query-for-excel-addin-in-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!