Conditional "OnAction" for vba-drawn buttons

sbedert

New Member
Joined
Oct 31, 2011
Messages
2
Hi,

I'm looking for a way to specify a parameter for an OnAction-setting of a vba-excel-drawn button.

The following piece of (non-working) code should illustrate the concept:
Code:
[COLOR=#000000]<STYLE>.alt2 font {font: 11px monospace !important;color: #333 !important;}</STYLE>[/COLOR]
 
[COLOR=#000000][FONT=Arial][SIZE=2]Sub dumpArray(inputArray() As Double)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   Set datasheet = outputWorkbook.Sheets("Results")[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   For i = 0 To UBound(inputArray)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]       datasheet.cells(i,1) = inputArray(i)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]       If inputArray(i) >= 25 Then[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]           addButton(i)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]       End If[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   Next i[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]End Sub[/SIZE][/FONT][/COLOR]
 
[COLOR=#000000][FONT=Arial][SIZE=2]Sub addButton(n As Integer)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   Set datasheet = outputWorkbook.Sheets("Results")[/SIZE][/FONT][/COLOR]
 
[COLOR=#000000][FONT=Arial][SIZE=2]   Set s = datasheet.Buttons.Add(datasheet.Cells(n,2).Left, _ [/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]                                                     datasheet.Cells(n,2).Top, 100, 12.75)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   s.OnAction = DoSomething(n)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]End Sub[/SIZE][/FONT][/COLOR]
 
[COLOR=#000000][FONT=Arial][SIZE=2]Sub DoSomething(n As Integer)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]   MsgBox "You want to do something with the value of inputArray(n)"[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial][SIZE=2]End Sub[/SIZE][/FONT][/COLOR]


</PRE>

<!-- END TEMPLATE: bbcode_code -->Any suggestions are welcome.

Thank you in advance.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,224,427
Messages
6,178,587
Members
452,860
Latest member
jroberts02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top