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

Add Code to ActiveX Control

Status
Not open for further replies.

mllex

Technical User
Nov 28, 2001
44
US
I want to add a control programmatically to a new worksheet:

ActiveSheet.OLEObjects.Add ClassType:="Forms.CommandButton1",Left:=72,Top:=72,Height:=20,Width:=100

Next, I want to add the following code to the button:

Load UserForm1
UserForm1.Show

Can anyone give me some tips on how to accomplish this? I tried the following, without success:

Public Sub Workbook_NewSheet(ByVal Sh As Object)

Load UserForm1
UserForm1.Show

End Sub

Thank you.
 
Hi,
After adding your commandbutton, VBA inserts the following in the sheet object:
Code:
Private Sub CommandButton1_Click()
   
End Sub
Here's where you want to insert your calls that will be executed upon the click event. Skip,
metzgsk@voughtaircraft.com
 
That makes sense. How can I do that in VBA?

Basically I am giving users a button which asks them questions and then produces a form for them to complete. Each new form needs to be on a new sheet, and I would like to put a command button on each sheet so that they can initiate the program again, if need be. So I need to make all of this happen when a new sheet is added.

?






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top