Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add an "Ok" button to a UserForm for Excel? 1

Status
Not open for further replies.

navyguy

Programmer
Aug 10, 2002
30
US
Hi, I just discovered that I can create custom UserForms with the visual basic editor for excel. This is new to me.

It ought to be simple but I cant seem to figure it out. I want to be able to have an "Ok" button on the form so that it closes after items are selected in the form.

 
If you go into the Visual Basic Editor and click "UserForm" from the "Insert" menu, the userform appears as well as a control toolbox. The plain grey rectangle icon is the "Command Button". Simply click this once to select and click once more on your userform to drop it. (You may need to click the toolbox command button to deselect it)

Pressing F4 brings up the properties of the button. From here you can change its caption etc.

Double-click your command button and enter the required VBA code in there.

Hope this helps



Clive [infinity]
 
ps - the VBA code to make a form disappear is
formName.hide (controls keep their values)
or
formName.unload (controls lose their values) Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top