Excel AddIn、.NET 4.0、NetOffice 1.5.1.2、ExcelDNA 1.29、C# 安装程序使用 VBA 调用 xls (install.xls),如下所示 在 install.xls 结束时,Excel 将关闭。但是,在 Excel 关闭后,Excel 崩溃说“Excel 停止工作......请向 Microsoft 发送报告”有两个按钮,一个是“不发送”,另一个是发送
这只发生在 Windows XP + Excel 2007 或 WinXP + Excel 2010 上。此外,在调试过程中,我注意到如果我用 MsgBox 替换 Application.Wait,则根本没有崩溃问题。我觉得有某种时间问题,但真的不知道没有控制。这个问题让我发疯。请帮忙。谢谢!
Private Sub Workbook_Open()
Dim quit As Integer
Dim added As Boolean
added = Add_Addin
Application.Wait (Now + TimeValue("0:00:02"))
If Workbooks.Count = 1 Then
Application.Wait Now + TimeValue("0:00:03")
Application.quit
Else
Application.Wait Now + TimeValue("0:00:03")
Me.Close
End If
End Sub
Private Function Add_Addin() As Boolean
On Error GoTo ERR_
Dim addinFile As String
addinFile = ThisWorkbook.Path & "\" & "MyAdd-In.xll"
If Len(addinFile) > 0 Then
Dim LEA As AddIn
Set LEA = Application.AddIns.Add(addinFile)
If (Not LEA Is Nothing) Then
LEA.Installed = True
Else
MsgBox "Failed to add XLL"
End If
'If (Application.RegisterXLL(addinFile) = True) Then
' MsgBox "Yeah, succeed registering XLL"
'Else
' MsgBox "Failed to register XLL"
'End If
Else
MsgBox "XLL file not found"
End If
addinFile = ThisWorkbook.Path & "\" & "MyFunc.xla"
If Len(addinFile) > 0 Then
Dim LEA2 As AddIn
Set LEA2 = Application.AddIns.Add(addinFile)
If (Not LEA2 Is Nothing) Then
LEA2.Installed = True
Else
MsgBox "Failed to add xla"
End If
Else
MsgBox "xla file not found"
End If
Add_Addin = True
Exit Function
ERR_:
MsgBox ("Error " & Err.Number & " " & Err.Description)
Add_Addin = False
End Function