gpt4 book ai didi

vba - 由于缺少引用xlam,Excel崩溃

转载 作者:行者123 更新时间:2023-12-03 16:02:42 29 4
gpt4 key购买 nike

我有两个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

关于vba - 由于缺少引用xlam,Excel崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284281/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com