XL98: How to Dynamically Resize a User Form
ID: Q188028
|
The information in this article applies to:
-
Microsoft Excel 98 Macintosh Edition
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, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft support professionals 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
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp Creating the User Form
To create a user form, follow these steps:
- Close all open workbooks, and open a new workbook.
- Start the Visual Basic Editor by pressing OPTION+F11.
- To create a blank User form, click UserForm on the Insert menu.
- 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 CommandButton, and draw two command buttons
that are aligned on the right side of the form.
- For the following properties, type the following values.
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
- On the Toolbox, click OptionButton, and draw two option buttons on the
form.
- For the following properties, type the following values.
OptionButton1:
Property Value
--------------------------------
Caption ExtraOption1
Left 264
Top 30 OptionButton2:
Property Value
--------------------------------
Caption ExtraOption2
Left 264
Top 54
- Set the Width property of the User form to 185.25.
Creating the Code
On the user form, double-click Expand, 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
Running the Macro
To run the macro, follow these steps:
- On the File Menu, click "Close and Return to Microsoft Excel."
- On the View menu, point to Toolbars, and then click Forms.
- On the Forms toolbar, click Button, and then draw a button on the
worksheet.
- When the Assign Macro dialog box is displayed, type ShowForm in the Macro Name box, and then click New.
- In the General module, type the following code:
Sub ShowForm()
UserForm1.Show
End Sub
- On the File menu, click "Close and Return to Microsoft Excel."
- Click the worksheet that contains the button.
- Click the button to run the ShowForm macro.
- Click Expand.
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 : kbprg kbdta xlvbahowto xlvbainfo
Version : MACINTOSH:98
Platform : MACINTOSH
Issue type : kbhowto
|