我有一些工作簿遇到与某些用户相同的问题。我们经历了检查COM加载项以及Windows和Office的各种组合的过程。
最后,我们将下面的代码作为workbook_beforeclose事件的一部分,并且问题已为我们的用户解决。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intResponse as Integer
'If the workbook needs to be saved then ask the user if they want to save the workbook, if not then exit without saving
'Need a global boolean to ensure the request to save the workbook is not shown twice
If Not ThisWorkbook.Saved And Not blnStartedClose Then
blnStartedClose = True
intResponse = MsgBox("Do you want to Save the this Workbook" & vbNewLine & vbNewLine & _
"Select 'Yes' to save the workbook" & vbNewLine & _
"Select 'No' to close without saving", vbYesNo, "Confirm - Workbook Save?")
If intResponse = vbYes Then ThisWorkbook.Save
End If
'If the user has clicked on 'No' to save the workbook then reset the "Saved" property to TRUE so that when we exit this routine no attempt to save the workbook is made
ThisWorkbook.Saved = True
End Sub
我发现,只要内存因某种原因而损坏,就会发生这种情况 - 因此很难找到问题的根源:例如,读取一个错误的指针引用,当您使用Windows API调用并使用错误的数据类型时(例如Long,LongPtr,..)可能很容易发生。 –