Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Event Code for Controls created at runtime...

Here is some code that creates a checkbos, and adds an event into the
worksheet code module.


'-----------------------------------------------------------------
Sub CreateCheckBox()
'-----------------------------------------------------------------
Dim oWs As Worksheet
Dim oOLE As OLEObject

Set oWs = ActiveSheet

Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", _
Left:=200, Top:=100, Width:=80, Height:=32)

'To set with a cell
'With Range("H2")
' Set oOLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", _
' Left:=.Left, Top:=.Top, Width:=.Width,
Height:=.Height)
'End With

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

(change the xxxx to gmail if mailing direct)
"Neily" wrote in message
...
Hi,

Is there a way of creating event code for a control that is created at
runtime?

For example, I have a form which based on a user created set of questions,
builds the form with a check box and combobox for each questions. I can't
predict how many questions the user will create.

I would like to be able to have a change event for the combo box that
switches the adjacent checkbox.

When the code creates the checkboxes and comboboxes, I have standard names
for them and just increment the number at the end of each. ie
chkMyCheck1,
chkMyCheck2, etc. I thought I might be able to write the change event
based
on what I know the name will be but just write more change events than I
would possibly need.

Basically, is there a dynamic in code way of doing this?

Ta.

Neily



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
Assigning events to runtime-created controls - is it possible? BizMark Excel Discussion (Misc queries) 1 November 20th 06 09:36 AM
Add controls to Frames at Runtime Neily[_3_] Excel Programming 4 October 31st 05 02:29 PM
add event to controls added in runtime Brotha lee Excel Programming 1 May 21st 05 10:32 AM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM
Add Controls With Events at Runtime llowwelll Excel Programming 10 May 24th 04 11:52 AM


All times are GMT +1. The time now is 07:34 PM.

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

About Us

"It's about Microsoft Excel"