1

I have a UserForm with a cancel button.

Sub DialogTest() MyForm.Show End Sub Private Sub CancelButton_Click() Unload Me End End Sub 

I also tried MyForm.Hide, End by itself, cmdExit_Click.

The cancel button does not close the dialog nor does it cause the debugger to come up.

4
  • yes, it is named CancelButton Commented Jun 9, 2018 at 4:16
  • where is the Unload Me code located? Commented Jun 9, 2018 at 4:18
  • i'm not really sure what you're asking... i provided the exact location of Unload Me in my code sample above... it's in Private Sub CancelButton_Click() Commented Jun 9, 2018 at 4:20
  • By where I meant Sheet, Module, or UserForm. I was only able to Unload the UserForm when the code was pasted in the UserForm (Which I accessed by double-clicking on the cancel-button from VBA) Commented Jun 9, 2018 at 4:34

1 Answer 1

5

I was only able to replicate your issue when the Unload Me Sub was pasted in a Worksheet or Module. When the Sub is in the Userform, it works fine.

Here, the code is pasted in a module and does not close the Userform

Instead, from VBE, double click on your UserForm, then double click on your Cancel Button.

Then paste the code here

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

perfect. thanks. im not sure why that is not made clear on any of the articles i googled all day. makes sense now

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.