我有两个Excel文件(一个是xlam,另一个是xlsm)。 xlsm引用了xlam。

如果在打开xlam之前打开xlsm,Excel会崩溃。

从xslm(使用任何编程方法)开始,有一种方法可以检查xlam是否打开,如果没有打开,请动态加载它或显示警告,指出退出前必须先打开xlam。

我编写了一些代码,这些代码从xlsm中的Workbook_Open子句中调用

Public Function checkReferences() As Boolean
On Error Resume Next

Dim retVal As Boolean
retVal = False

Dim i As Integer

For i = 1 To ThisWorkbook.VBProject.References.Count
    With ThisWorkbook.VBProject.References(i)
        If StrComp(.name, "PreTradeServices") = 0 Then
            retVal = True
            Exit For
        End If
    End With

Next i

checkReferences = retVal
End Function

不幸的是,Excel在达到Workbook_Open之前崩溃了

最佳答案

像这样吗

    '/**
     '
     ' VBA Function to check whether required addin is installed...
     ' @version 1.0
     ' @author Ilyas Kazi http://ilyaskazi.com
     '
     ' @param string str_filename (to parse file name to lookup for the addin)
     '
     ' @return boolean (true/false)
     '
   '**/
Function IsAddin_Installed(str_filename As String) As Boolean
    Dim aiwb As AddIn     'addin workbook

    For Each aiwb In Application.AddIns     'Loop through each addin workbook
        If UCase(aiwb.Name) = UCase(str_filename) Then
            IsAddin_Installed = True     'found
            Exit Function
        Else
            IsAddin_Installed = False
        End If
    Next

End Function

08-08 02:07