Excel-VBA显示警告如果没有安装插件

我正在使用Excel 2013文件,该文件由我更新为使用PowerQuery更容易导入数据。

它已经使用VBAmacros,我想包括一个警告/ MsgBox链接下载PowerQuery,如果它尚未安装。

我将如何检查主机系统上的PowerQuery的存在?

在我提供给你的链接上修改Rory的代码将会有类似下面的内容。 注意:您可以使用Rory的附加代码来处理2016版本或更早版本,以确保是否安装了现有程序。

由于您无法直接使用超链接,因此我在此调整了WiktorStribiżew的代码,允许用户在获取msgbox说未安装后单击“确定”进入下载网站。

Option Explicit Private Sub IsPowerQueryAvailable() Dim downloadlink As String downloadlink = "https://www.microsoft.com/en-gb/download/details.aspx?id=39379" Dim bAvailable As Boolean If Application.Version >= 16 Then bAvailable = True Else On Error Resume Next bAvailable = Application.COMAddIns("Microsoft.Mashup.Client.Excel").Connect On Error GoTo 0 If Not bAvailable Then DownloadPowerQuery downloadlink End If End Sub Private Sub DownloadPowerQuery(downloadlink As String) Dim objShell As Object Dim Message As String Dim Wscript As Object Set objShell = CreateObject("Wscript.Shell") Message = MsgBox("Would you like to download PowerQuery?", vbYesNo, "Powerquery not available") If Message = vbYes Then objShell.Run (downloadlink) Else Wscript.Quit End If End Sub