我有一些工作簿遇到與某些用戶相同的問題。我們經歷了檢查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,..)可能很容易發生。 –