The following code which asks the user if he wants the version changed before saving, works perfectly well, apart from the fact that it crashes with a 'Microsoft Excel has stopped working' error message when quitting the subroutine. I've trapped it and it crashes after executing End Sub.
Has anyone any idea what the problem is or failing that, an alternative solution?
Thanks
Simon
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)]
Dim Ver As String
Dim Vern As Single
Dim Ans As Variant
Dim FName As String
Dim FPath As String
Ans = MsgBox("Do you want to up-version before saving?" & vbCrLf & "Alternatively Cancel to not save at all.", vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbCancel
Cancel = True
Exit Sub
Case vbNo
Exit Sub
Case vbYes
' Want to keep decimal places in version
Ver = ActiveWorkbook.CustomDocumentProperties("Version")
Vern = Val(Ver) + 0.01
Ver = Str(Vern)
ActiveWorkbook.CustomDocumentProperties("Version") = Ver
FPath = ActiveWorkbook.Path
FName = FPath & "\Audit_v" & Ver & ".xlsm"
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=FName
Application.EnableEvents = True
End Sub
Has anyone any idea what the problem is or failing that, an alternative solution?
Thanks
Simon