I was editing a user form today when I accidentally created a user form that could not be closed:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' Logic that always evaluated to:
Cancel = True
End Sub
The ShowModal
property is set to True, so you can't interact with Excel or the VBE so it's seemingly impossible to kill the form. The logic always evaluates to Cancel = True
regardless of CloseMode (e.g., Alt-F4). The final solution was to save the workbook and use the Task Manager to end Excel. This worked, as all information was correctly saved, but this is a rather dirty solution I'd rather avoid.
These questions:
deal with improperly closing the workbook which causes some error where it persists.
Is there a way to close a user form (that is already loaded) when Cancel
always equals True
in the Query_Close
event?