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
retV开发者_开发技巧al = 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
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
What about adding the XLAM as a VBA reference? Is there a way you can keep the XLAM in a centralized location?
精彩评论