I am trying to create a macro on a userform which displays a message box, which closes the active workbook without saving when yes is clicked.
The below code is giving me run time error 1004 Method 'Close' of object 'Workbook' failed:
Private Sub CommandButton2_Click()
Msg = "This action will close "
Msg = Msg & ActiveWorkbook.Name & " Do you wish to continue?"
Ans = MsgBox(Msg, vbQuestion + vbYesNo)
Select Case Ans
Case vbYes
ActiveWorkbook.Close savechanges:=False
Case vbNo
Exit Sub
End Select
End Sub
Bookmarks