X button at top right of userforms

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey

A workbook opens when a userform is loaded. I have it
setup for that same workbook to close when the
commandbutton named "Close" is clicked, but I also would
like to get it to where it closes when the X at the top
right of the userform is clicked as well. I dont know
what event this would be. How would I get it to do this?


Thank you
Todd Huttenstine
 
Todd,

The UserForm_QueryClose event will fire when the user closes the
form with the X button in the top right of the form.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Todd,

That is Query

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
'do your stuf
End If
End Sub

You could even trap the un load from within code (such as your button) by
checking vbFormCode as well.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top