2010-11-26 108 views
0

我有两个Excel文件(一个是xlam,另一个是xlsm)。 xlsm引用xlam。由于缺少引用xlam而导致Excel崩溃

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

从xslm(使用任何编程方法)是否有一种方法可以检查xlam是否打开,如果不是,请动态加载它或显示xlam需要在退出之前先打开的警告。

我制作的一些代码,被从Workbook_Open子在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 

不幸的Workbook_Open之前的Excel崩溃达到

回答

1

像这样的事情?

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

不起作用恐怕xlam并未列在Application.Addins中 – Pram 2010-11-29 15:20:55

0

将XLAM添加为VBA参考怎么样?有没有办法让XLAM保持在中央位置?

+0

xlam已经是VBA参考 – Pram 2010-11-30 09:54:19

相关问题