PDA

View Full Version : Solved: Minimizing UserForms



MWE
03-05-2005, 06:01 PM
I have a UserForm that is displayed with vbModeLess. So it stays on the screen and can be moved around while the application does other things. It is closed by clicking on the X in the upper right corner. Many instances of this UserForm might be displayed at any time (with different "data"). To minimize screen clutter, I wish to allow the user to minimize individual instances. Before I add Min and Max command buttons and the necessary code, I wish to ask if there is a way to set up a UserForm such that the "standard window" buttons: Min; Normal; and Close (X) are availabe for UserForms (to the right of the Caption bar).

Thanks

Jacob Hilderbrand
03-05-2005, 06:28 PM
See this KB Entry (http://www.vbaexpress.com/kb/getarticle.php?kb_id=165).

Scottie P
03-05-2005, 06:34 PM
HI MWE,

no there are not settings in the Userform properties to allow for such items, but as Jake has pointed out, there is a great example of how to do so using a little code - and this example will work with ShowModal set to 'false'.

Scott

MWE
03-05-2005, 06:51 PM
See this KB Entry (http://www.vbaexpress.com/kb/getarticle.php?kb_id=165).
this code does not do what the description says:

Assuming that commandbutton1 is actually created, when clicked it unloads the form
I can change that, but no button is created anywhere on the form.

Scottie P
03-05-2005, 06:58 PM
MWE,

the minimize button is on the frame (Titlebar) in the upper right.
And commandbutton (Labeled 'Close') is created in the field of the userform.

Leaving the commandbutton on the userform field to close the userform is optional, of course.

MWE
03-05-2005, 08:55 PM
MWE,

the minimize button is on the frame (Titlebar) in the upper right.
And commandbutton (Labeled 'Close') is created in the field of the userform.

Leaving the commandbutton on the userform field to close the userform is optional, of course.
Scott, thanks for you timely help.

I figured out why this did not work initially. I was changing the UserForm caption programatically and that overwrote the buttons previously added. I moved the location where the proc FormatUserForm is called so the programatic revision to the UserForm caption occurs before the call that adds the buttons. I apologize for suggesting that the code did not work. BUT it does not do precisely/all that the description indicates. Once I sorted out the caption overwriting problem and got that working, I noticed that some features were still not working as advertised. So, I created an Excel test application. I used the code precisely as offered and placed it in the module locations indicated. Results:




two buttons are added to the frame:

a "minimize" button: this button does minimize the UserForm
a button that suggests "maximum" (icon is small square, left, right and bottom are gray, top is black): this button does not seem to do anything

when the UF is minimized,




the left button (was minimize) is now "return to original size", and that works as it should
the center button is the same as above and still does not do anything

commandbutton1 (labeled "Close" or otherwise) is not created anywhere.
Neither of these issuses is a big problem for me, but suggests something is amiss. This may be a version issue. I am running MSForms 2.0 and tested this code in Excel2000, Word2000 and MSProject2000. Same results in each test.

Scottie P
03-05-2005, 09:07 PM
MWE,

glad you were able to get it working.
It is funny that you mention the name change issue - I was just reading about a similar problem elsewhere, but the resolve seemed to be a bit much to me.

Anyway, I am running this in XL2002 - I did not try it in 2000.
I am not sure why the button does not create on the userform field for you...it could be a version issue or Ref issue (not sure).

In any event, the max button doesn't seem to have any effect on several examples that I have seen (Jake's version, Ivan Moala's version, Colo's version, etc). I think that there is a reason for this, but I am hard pressed to remember it.

I guess the question is now, will this solution work for you?

MWE
03-05-2005, 09:20 PM
Scott: the solution in hand is adequate for now. As per you IM, I will look at other options as time permits.

Many thanks.

Ivan F Moala
03-07-2005, 01:26 AM
Hi MWE, the reason the Max button doesn't work is because it is coded like this. ie it disables the Max button.

The KB code is not transparently evident that it doesn't do this as there are no flags used to show the controls.
The other thing with the KB code is that it really just minimizes to the XL desk, not a true Min to taskbar. To do this requires a little more.

If you look here

http://www.xcelfiles.com/Userform_TaskBar.html

It has a Workbook that has a technique to Min to the taskBar with an Icon
It has set by default the Max button disabled ... to enable this just reset the flags



'// lStyle is the New window style so lets set it up with the following
lStyle = lStyle Or WS_SYSMENU '// SystemMenu
lStyle = lStyle Or WS_MINIMIZEBOX '// With MinimizeBox
lStyle = lStyle Or WS_POPUP Or WS_MAXIMIZEBOX '// and MaximizeBox


The reason the Max button is disable is that it serves no purpose UNLESS you can resize all other controls within the userform. Have a look @ Steven's site for Formfun to do this ...

http://www.bmsltd.ie/Excel/Default.htm