PDA

View Full Version : Userform Unloads as soon as Initialized



RECrerar
10-05-2007, 07:06 AM
This is a followon from the 'Select Directory Only' Thread, http://vbaexpress.com/forum/showthread.php?t=15341 but a different issue so thought it would be more appropriate to start a new thread.

The userform to select a directory, works fine when it is run by itself, but when it is incorporated in the macro the userform unloads as soon as the Userform_Initialize sub is completed. This then causes the rest of the program to crash as Directory="" rather than that which should be specfied by the form.

I've attached the file for people to look at, and if anyone could help that would be great.

PS. Sorry for the barrage of questions today, really don't get the word VBA and this small simple project is proving a nightmare, but hopefull monday I'll be back to lovely Excel and things will make sense again

RECrerar
10-05-2007, 07:53 AM
Hi again, hopefully last post of the day.

I have solved this by splitting the code into two subs, the second one of which is called from the userform and contains all the code that follwed the user form.

I would appreciate it if someone could just confirm that this is the way Wrod works and that in order for a userform to stay visible on the screeen it must be the last thing called in a sub and then any further code should be started from the userform.

shasur
10-06-2007, 07:42 PM
You can also set the useform as modal:

GetDirectory.Show 1

when the useform is modal, subsequent code will be executed only after the user responds to the userform