Excel宏-测试是否已安装Power Query for Excel Addin [英] Excel Macro - Test if Power Query for Excel Addin in installed

查看:63
本文介绍了Excel宏-测试是否已安装Power Query for Excel Addin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以测试是否安装了"Power Query for Excel"加载项并使用excel宏启用?我想用它来授权工作簿的数据刷新,该工作簿使用此加载项连接到多个数据源.

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.

感谢和问候.

推荐答案

您可以使用像这样的东西,因为它是COM加载项:

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

这篇关于Excel宏-测试是否已安装Power Query for Excel Addin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆