Closing the Userform when macro is running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've created an add-in that, upon pressing the button, a userform appears and different macro codes execute depending on the user's command-button choice.

After the user presses a command button, the macro springs into action, and will often run for 1min or so. What I would like to do is to have that userform close after the user presses the command button and starts off the macro.

My setup is like this:

Add-in button code:

Sub ShowForm()

Myform.show

End Sub
 
Something like:

Unload UserForm1

should do it.

--

Vasant

SuperJas said:
Hi,

I've created an add-in that, upon pressing the button, a userform appears
and different macro codes execute depending on the user's command-button
choice.
After the user presses a command button, the macro springs into action,
and will often run for 1min or so. What I would like to do is to have that
userform close after the user presses the command button and starts off the
macro.
 
Hi Vasant,

Thanks for your tip. However, I've tried it and it still doesn't unload/hide as I'd like.

I've pasted the "Unload Myform" line in the command-button code section. When I run the code via the "Step-into" method, the userform does close, but when I run it normally it doesn't...

So I'm thinking this might have something to do with the "Application.Screenupdating=False" command. However, this line is below the "Unload Myform" line, so I can't figure out what the problem is...

Thanks for your time!




----- Vasant Nanavati wrote: -----

Something like:

Unload UserForm1

should do it.
 
Jas,

You might want to try Userform1.Hide and/or DoEvents to make the form
display go away. Are you using a modeless form?

Alex J

SuperJas said:
Hi Vasant,

Thanks for your tip. However, I've tried it and it still doesn't unload/hide as I'd like.

I've pasted the "Unload Myform" line in the command-button code section.
When I run the code via the "Step-into" method, the userform does close, but
when I run it normally it doesn't...
So I'm thinking this might have something to do with the
"Application.Screenupdating=False" command. However, this line is below the
"Unload Myform" line, so I can't figure out what the problem is...
 
If you don't want to close the form out completely you can use:

UserForm1.Hide instead of Unload UserForm1
 
Hi Alex,

Thanks for your tip! It turned out that the "DoEvents" command was needed to hide/close the userform.

kfarmer, thanks for your suggestion. I haven't given much thought as to whether to unload or hide the form...would the choice affect performance? For now I've chosen the hide property purely because I'm more used to that...

Thanks, Vasant, Alex, and Kfarmer for your time! =)

Jas.
 
Back
Top