Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default add event to controls added in runtime

Hi,

I can not figure this out!

Does anybody knows how you can add events to controls added in runtime on a
userform.

I use the following code to:

myheight = 12
mytop = 70
mywidth = 12
myleft = 12
Set Mycmd = Controls.Add("Forms.CommandButton.1", "Test")
Mycmd.Left = myleft
Mycmd.Top = mytop
Mycmd.Width = mywidth
Mycmd.Height = myheight

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default add event to controls added in runtime

Here is a working example

'-----------------------------*------------------------------*------
Sub CreateControlButton()
'-----------------------------*------------------------------*------
Dim oWs As Worksheet
Dim oOLE As OLEObject
Dim myheight, mytop, mywidth, myleft, mycmd
myheight = 12
mytop = 70
mywidth = 12
myleft = 12
Set oWs = ActiveSheet
Set oOLE = _
oWs.OLEObjects.Add(ClassType:="Forms.CommandButton .1", _
Left:=myleft, Top:=mytop, Width:=mywidth,
Height:=myheight)
With oOLE
.Object.Caption = "Run myMacro"
.Name = "myMacro"
End With
With ThisWorkbook.VBProject.VBComponents(oWs.CodeName). CodeModule
.InsertLines .CreateEventProc("Click", oOLE.Name) + 1, _
vbTab & "If Range(""A1"").Value 0 Then " & _
vbCrLf & _
vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _
vbTab & "End If"
End With
End Sub


--
HTH

Bob Phillips

"Brotha lee" wrote in message
...
Hi,

I can not figure this out!

Does anybody knows how you can add events to controls added in runtime on

a
userform.

I use the following code to:

myheight = 12
mytop = 70
mywidth = 12
myleft = 12
Set Mycmd = Controls.Add("Forms.CommandButton.1", "Test")
Mycmd.Left = myleft
Mycmd.Top = mytop
Mycmd.Width = mywidth
Mycmd.Height = myheight



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox added to Form at runtime too small, can't control size andchange event won't trigger RCGUA Excel Worksheet Functions 2 December 10th 08 09:34 PM
Textbox added to Form at runtime too small, can't control size andchange event won't trigger RCGUA Excel Worksheet Functions 0 December 10th 08 07:48 PM
Event procedures for controls added with CreateEventProc John Austin[_6_] Excel Programming 7 March 24th 05 03:21 PM
Event procedures for controls added with CreateEventProc John Austin[_5_] Excel Programming 0 March 12th 05 09:33 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM


All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"