The following code works well to rename activeworkbook and remove the old workbook when it detects content changes. [like a time-stamp saving ]
However, after execution, the Excel application itself just crashes down even "On Error Resume Next" is included.
Nonetheless, I can still open the newly renamed workbook successfully ( all changed content also remains successfully)
But it is strange and inconvenient in the way that, whenever I press [save], the Excel closes itself. And I get to re-open the workbook to continue working on it instead of being able to stick continuously to the activebook for further editing.
Anything wrong?
I am currently using Excel 2012.
Thanks!
Below is the crash report:
問題簽章:
問題事件名稱: APPCRASH
應用程式名稱: EXCEL.EXE
應用程式版本: 15.0.4535.1507
應用程式時間戳記: 52282d17
錯誤模組名稱: EXCEL.EXE
錯誤模組版本: 15.0.4535.1507
錯誤模組時間戳記: 52282d17
例外狀況代碼: c0000005
例外狀況位移: 000000000013f642
作業系統版本: 6.1.7601.2.1.0.256.48
地區設定識別碼: 3076
與問題相關的其他資訊:
LCID: 1028
skulcid: 3076
閱讀我們的線上隱私權聲明:
Windows 7 Privacy Statement
Thanks a lot!
However, after execution, the Excel application itself just crashes down even "On Error Resume Next" is included.
Nonetheless, I can still open the newly renamed workbook successfully ( all changed content also remains successfully)
But it is strange and inconvenient in the way that, whenever I press [save], the Excel closes itself. And I get to re-open the workbook to continue working on it instead of being able to stick continuously to the activebook for further editing.
Anything wrong?
I am currently using Excel 2012.
Thanks!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error Resume Next
'---------------------
With ActiveWorkbook
'---------------------
' [ Unsave if no changes ]
If (.Saved = True) Then
Cancel = True
Exit Sub
End If
'---------------------
' [ Save if changes ]
old_path = .FullName
new_path = .Path & "\" & "Test" & Format(Now(), "yy-mm-dd")
Cancel = False
If Dir(new_path, vbNormal) <> "" Then
DoEvents
Else
.SaveAs Filename:=new_path, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
Kill (old_path)
End If
'---------------------
End With
End Sub
Below is the crash report:
問題簽章:
問題事件名稱: APPCRASH
應用程式名稱: EXCEL.EXE
應用程式版本: 15.0.4535.1507
應用程式時間戳記: 52282d17
錯誤模組名稱: EXCEL.EXE
錯誤模組版本: 15.0.4535.1507
錯誤模組時間戳記: 52282d17
例外狀況代碼: c0000005
例外狀況位移: 000000000013f642
作業系統版本: 6.1.7601.2.1.0.256.48
地區設定識別碼: 3076
與問題相關的其他資訊:
LCID: 1028
skulcid: 3076
閱讀我們的線上隱私權聲明:
Windows 7 Privacy Statement
Thanks a lot!
Last edited: