如何检查是否为具有VBA的Macintosh用户安装了Excel加载项

时间:2018-07-18 15:08:59

标签: excel vba macos excel-vba

使用VBA,我可以检测是否为Windows Microsoft Office-Excel安装了特定的加载项,但是在MacOS Microsoft Office-Excel中执行时,相同的代码无法检测。

以下是我尝试在Macintosh的Microsoft Excel 2016中执行的代码示例。

Private Sub Workbook_Open()

rw = 0
flag = 0
If InStr(Application.OperatingSystem, "Macintosh") Then
For Each ad In Application.AddIns
    If flag > 0 Then
        Exit For
    Else
        If InStr(ad.Name, "Vena") Then
            MsgBox "Vena add-in is installed."
            flag = 1
        Else
            MsgBox "Vena add-in is not installed."
        End If
        rw = rw + 1
    End If
Next
Else
MsgBox "Vena is not compatible with your Operating System."
End If
End Sub

在MacOS Microsoft Office环境中,已安装Excel加载项。但是,当我执行代码时,系统会通知我未安装该加载项。错误消息的屏幕截图:

img1

1 个答案:

答案 0 :(得分:2)

如果您安装了任何其他加载项,您的代码将显示该消息,因为它会显示名称中没有Vena的任何加载项的消息。我建议像这样:

Private Sub Workbook_Open()

rw = 0
flag = 0
If InStr(Application.OperatingSystem, "Macintosh") Then
    For Each ad In Application.AddIns
        If InStr(1, ad.Name, "Vena", vbtextcompare) Then
            MsgBox "Vena add-in is installed."
            flag = 1
            Exit For
        End If
    Next
    If flag = 0 then MsgBox "Vena add-in is not installed."
Else
    MsgBox "Vena is not compatible with your Operating System."
End If
End Sub