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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms in excel 2

Status
Not open for further replies.

ETID

Programmer
Jul 6, 2001
1,867
US
I've never used a form in excel,...I have in access.

So using the defaults...
I have UserForm1 with some radio buttons in it, residing in UserForm1 (userform)

My question is how do I activate it from code?

What is the syntax?

or better yet, could anyone post an example?

Thanks.
 
A quick way (for testing and development) is just to press F5 (or click the run tool) from the VBA editor when the form window has focus.

To use code, you can simply do this:
[blue]
Code:
Sub test()
  UserForm1.Show
End Sub
[/color]

In Excel 97, this will activate the form as Modal, meaning that focus will stay on the form until closed.

In Excel 2000 or later, this will activate the form as Modeless, meaning you can click on the worksheet and do stuff there while the form is still active. If you want to activate the form as Modal, you can use an optional parameter:
[blue]
Code:
Sub test()
  UserForm1.Show vbModal
[green]
Code:
  'Default is vbModeless
[/color]
Code:
End Sub
[/color]

And you can run a macro by putting the cursor somewhere between the Sub and End Sub and press F5.


 
OK, let's take this a step further. Let's suppose that I want my UserForm to Show each time the workbook opens. I am looking for the event for which to write a procedure that can show the form.
 
alt + f11

then in the VBAProject window dbl click "ThisWorkbook"

then in the code window...where the drop downs marked general and declarations, choose workbook and open respectively.


paste your code in the sub that the editor provides for the event selected.
 
Thanks ETID. I found the same answer, and the name of the event procedure, in another thread shortly after I posted the message to which your replied.

I have that code working; now, I just need to figure out if I can position the form a tad more precisely than seems to be allowed by the initial position property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top