I am trying to create a macro that will give me a message box before closing Excel to ask if I want to save changes. When I select No from the message box the message pops up again, then the 2nd time that I chose No it does close.
I don't know very much about VBA programming, I just try to record macro's then edit them slightly. I also search online and copy paste. This is how I put together this code below but obviously something is wrong. (although it works) I wonder if someone could advise me what needs to be changed in this code. Any help appreciated, Thanks
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim answer As String
Dim question As String
Dim OrigName As String
question = "Do you want to save Changes?"
answer = MsgBox(question, vbYesNoCancel)
If answer = vbCancel Then
Exit Sub
End If
If answer = vbNo Then
ActiveWorkbook.Close SaveChanges:=False
End If
If answer = vbYes Then
ActiveWorkbook.Save
ActiveWorkbook.SaveAs ("C:\Users\me\Documents\reports\Backup\" + ActiveWorkbook.Name & Format(Now(), "DD-MMM-YYYY hh-mm") & ".xlsm")
Exit Sub
End If
End Sub