Exiting a Routine

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
I have an On Open procedure that calls a Userform with instructions. On this UserForm I have two command buttons. One is labeled continue and hides the UserForm. I would like the other one to allow the user to hide the user form and Exit the On Open procedure. Exit Sub only exits the OnClick routine. How do I exit the On Open routine?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Lenze.
This assumes your form is being shown modally.
Dim a public boolean in a standard module.
for ex. Public ExitNow as Boolean
Put a line such as this in your OnOpen procedure immediately following your Show statement:

If ExitNow then Exit Sub

In your cmdExitOnOpen_Click event, commandbutton to end the OnOpen procedure, set ExitNow to = TRUE.

Tom
This message was edited by TsTom on 2002-10-04 10:23
 
Upvote 0
So simple I overlooked the obvious. Thanks Mudface

Edit:
Tom:
For what I need the End statement seems to work, but I also like your approach. I do have a need for this is a similar application.
Thanks
This message was edited by lenze on 2002-10-04 10:28
 
Upvote 0
Hi Lenze.
The end statement will unload your userform.
You mentioned that you only wanted to hide it. The end statement should be used sparingly.
Tom

PS Search the "End Staement" in VBA help and see the remarks at the bottom.
This message was edited by TsTom on 2002-10-04 10:44
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,532
Members
444,794
Latest member
HSAL

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