问题
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