Microsoft KB Archive/188028

= MacXL: How to Dynamically Resize a User Form =

Article ID: 188028

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Excel 2001 for Mac
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q188028





SUMMARY
This article describes how to create a custom user form that dynamically changes size to show more options when you click a button.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

How to Create the User Form
To create the user form, follow these steps:  Close all open workbooks, and open a new workbook. Start the Visual Basic Editor (press OPTION+F11). Click UserForm on the Insert menu to create a blank user form. If the Properties window is not visible, click Properties Window on the View menu. Type the following values for the Height and Width properties for UserForm1:

Height: 149

Width: 352

 On the Toolbox, click the CommandButton icon, and draw two command buttons that are aligned on the right side of the form.</li>  For the following properties, type the following values. <pre class="fixed_text">  CommandButton1:

Property           Value -     (Name)              btnExpand Caption            Expand Height             24 Width              54 Left               6 Top                6

CommandButton2:

Property           Value ---     (Name)              btnContract Caption            Contract Height             24 Width              54 Left               6 Top                36 </li> On the Toolbox, click the OptionButton icon, and draw two option buttons on the form.</li>  For the following properties, type the following values. <pre class="fixed_text">  OptionButton1:

Property           Value Caption            ExtraOption1 Left               264 Top                30

OptionButton2:

Property           Value Caption            ExtraOption2 Left               264 Top                54 </li> Set the Width property of the user form to 185.25 .</li></ol>

How to Create the Code
Double-click the Expand command button on the user form, and type the following code in the Code module for the user form: Sub btnExpand_Click UserForm1.Width = 352.5 End Sub

Sub btnContract_Click Userform1.Width = 185.25 End Sub

How to Run the Macro
To run the macro, follow these steps: <ol> On the File menu, click Close and Return to Microsoft Excel.</li> On the View menu, point to Toolbars, and then click Forms.</li> On the Forms toolbar, click the Button icon, and then draw a button on the worksheet.</li> When the Assign Macro dialog box is displayed, type ShowForm in the Macro name box, and then click New.</li>  Type the following code in the General module: Sub ShowForm UserForm1.Show End Sub </li> On the File menu, click Close and Return to Microsoft Excel.</li> Click the worksheet that contains the button.</li> Click the button to run the ShowForm macro.</li> Click the Expand button.</li></ol>

The dialog box expands, and you can see the option buttons. If you click Contract, the dialog box is reduced in size, and you no longer see the option buttons.

Additional query words: XL98

Keywords: kbhowto kbprogramming KB188028

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.