1
votes

I have two Excel files (one a xlam and the other a xlsm). The xlsm references the xlam.

If I open the xlsm before opening the xlam, Excel crashes.

From with the xslm (using any programmatic method) is there a way I can check to see if the xlam is open and if not, either load it dynamically or show a warning that the xlam needs to be opened first before exiting.

I crafted some code which gets called from the Workbook_Open sub in the xlsm

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

Unfortunately Excel crashes before that Workbook_Open is reached

2

2 Answers

1
votes

Something like this?

    '/**
     '
     ' 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
0
votes

What about adding the XLAM as a VBA reference? Is there a way you can keep the XLAM in a centralized location?