UserForm.Show opens a userform, now how do I close it?

OdinsDream

Well-known Member
Joined
May 19, 2002
Messages
541
I've got a user form with boxes for values, and a Submit button.

When the Submit button is clicked, I want to do something with the values, and then close the userform, allowing the macro to continue where it left off.

I don't see anything like UserForm.Close. The closest I can find is Enabled, but I'm not sure if that's proper in this situation.

Any help appreciated. Thanks a lot!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
unload userform is the command to close the userform
or
me.unload
userform.hide will hide the form but not close it, if you need it again and don't what to repopulate it.
 
Upvote 0
Ok, that worked great. I have a follow-up question.

When the macro runs, the first thing I do is Application.ScreenUpdating = False, of course. The UserForm is then presented, and values are entered. When it closes, the image of the form remains on-screen (even though it's not there) because ScreenUpdating is off....
 
Upvote 0
I surrounded the call to UserForm.Show with screenupdate toggling...

Application.ScreenUpdating = True
UserForm.Show
Application.ScreenUpdating = False

And the form was still left on the screen. The solution ended up putting a Window().Activate statement after the Show command.
 
Upvote 0
Are you using XP, the Screenupdating function in xp is different to the previous versions and is a pain in the *** to use with userforms.

BRett
 
Upvote 0
Hi OdinsDream,

Could you post details of the code that you are using? The advice given by Dragracer should have worked, but I don't follow the logic of the example in your last post - you have true first and then false.

By way of example, the following routine calls a simple userform and the second routine (UserForm_Activate) is located within the form itself.<pre>
Sub test()

Application.ScreenUpdating = False
'
'your code here
'
UserForm1.Show
'
Application.ScreenUpdating = True

End Sub</pre><pre>

Private Sub UserForm_Activate()
Application.Wait (Now + TimeValue("0:00:04"))
Unload Me
End Sub</pre>

Any good?


_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-07-30 03:48
 
Upvote 0
Hi, sorry if my previous post was confusing. Here's the idea.

My macro runs and turns off screen updating, using only the status-bar for updates. The user form in question is not guranteed to be called, but depends on conditions.

If the userform is required, I called UserForm.Show. After I was done, and unloaded the form, the image remained, since screen updating was off.

I then tried turning screen updating on, right before Show. Then, of course, turning it back off after Show had finished.

When I tried this, it still failed. The solution ended up putting the statement Windows("Special Tasks.xls").Activate directly after UserForm.Show, then turning screen updating off.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,033
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top