Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Assign macros to dynamically created form elements

Hello,

I have a form where all elements (dropdowns, checkboxes, etc.) are
created dynamically from the values of an excel sheet.

How can I assign a macro to a form element? When the form element is
actually drawn in the VBA editor, I can use a "Private Sub
btn_Info_Click()", but this is obvoiusly not possibe in this case.

Does anyone knwo a solution?

Regards,
Joepy
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Assign macros to dynamically created form elements


.OnAction property?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joepy" wrote in message
om...
Hello,

I have a form where all elements (dropdowns, checkboxes, etc.) are
created dynamically from the values of an excel sheet.

How can I assign a macro to a form element? When the form element is
actually drawn in the VBA editor, I can use a "Private Sub
btn_Info_Click()", but this is obvoiusly not possibe in this case.

Does anyone knwo a solution?

Regards,
Joepy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Assign macros to dynamically created form elements

Thanks for the mails I received so far.
Unfortunately, none of the solutions work:

Maybe you know what I mean when you look at the following example:

Private Sub UserForm_Initialize()

Set MyButton = Me.Controls.Add("Forms.CommandButton.1", "button01")

MyButton.Top = 25
MyButton.Left = 12
MyButton.Width = 72
MyButton.Height = 24
MyButton.Caption = "Click Me"
'MyButton.OnAction = Test

End Sub

This creates a button on the form. The last line (where I used
'onAction') should assign a macro ("Test") to the button. However,
'onAction' doesn't work. I really hope there is a way I can get this
to work.

Any help is really appreciated.

Joepy
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Assign macros to dynamically created form elements

Joepy,

I don't thoink we appreciated that you meant a button on a worksheet.

A different approach.

Add a class module, and add the code belows. Name the clas module clsButtons

'===============================================

Public WithEvents Buttons As MSForms.CommandButton

Private Sub ButtonS_Click()
'add your specific code here
MsgBox "You clicked: " & Buttons.Caption
End Sub


And finally, create your button this way.


'===============================================

Dim myButton

Set myButton = Me.Controls.Add("Forms.CommandButton.1", "button01")
Set formButton = New clsButtons
Set formButton.Buttons = myButton
collBtn.Add formButton

myButton.Top = 25
myButton.Left = 12
myButton.Width = 72
myButton.Height = 24
myButton.Caption = "Click Me"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joepy" wrote in message
om...
Thanks for the mails I received so far.
Unfortunately, none of the solutions work:

Maybe you know what I mean when you look at the following example:

Private Sub UserForm_Initialize()

Set MyButton = Me.Controls.Add("Forms.CommandButton.1", "button01")

MyButton.Top = 25
MyButton.Left = 12
MyButton.Width = 72
MyButton.Height = 24
MyButton.Caption = "Click Me"
'MyButton.OnAction = Test

End Sub

This creates a button on the form. The last line (where I used
'onAction') should assign a macro ("Test") to the button. However,
'onAction' doesn't work. I really hope there is a way I can get this
to work.

Any help is really appreciated.

Joepy





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
How do I assign a unique ID number to an invoice sheet I created? Matt Excel Worksheet Functions 2 March 30th 06 06:08 PM
I created a form on excel. want to edit the form without printing Oz Excel Discussion (Misc queries) 1 September 1st 05 08:18 PM
Scaling a chart that has been dynamically created in vb Mark Charts and Charting in Excel 3 May 27th 05 08:16 PM
How do I assign a macro I have created to a Command Button in Exc. Andrew7675 Excel Discussion (Misc queries) 1 March 3rd 05 08:08 PM


All times are GMT +1. The time now is 06:17 PM.

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"