Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Close operation in VBA

  Asked By: Karina    Date: Nov 07    Category: MS Office    Views: 812
  

I want to do some operation when the main userform is going to close by clicking
on the close button on the form. Could you please help me out on the same.
For instance : private sub auto_open, Do we have any other function which can
operate when the close button is going to press.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Volney Fischer     Answered On: Nov 07

Not clear whether the close  button is a button  you've created, or if it is
the X on the form.

If it's a button, then use its click event.

If it's the X, then look at the terminate and deactivate events for the
form. I think it's the terminate event you want, but put code in for both.

 
Answer #2    Answered By: Sophie Campbell     Answered On: Nov 07

If it is controlling the closing of the userform, using the X button, you can
put this code in the userform  module:

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the OK button."
End If
End Sub

If you are talking about using a command button  on the userform, you need
something like this in the userform module:

Private Sub CommandButton1_Click()
'CommandButton1 is the name assigned to your userform control button.
'Your macro code goes here.
End Sub

 
Didn't find what you were looking for? Find more on Close operation in VBA Or get search suggestion and latest updates.




Tagged: