Results 1 to 4 of 4

Passing parameters to button OnAction calls

Threaded View

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    Eindhoven, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    2

    Passing parameters to button OnAction calls

    I'm currently working on a sheet that has a graph displaying the cost of several different solutions to a problem. Underneath this graph is a series of buttons that the user can press to get more details about a certain solution. The amount of solutions is variable, and, as such, so is the amount of buttons.

    I create the buttons using the code below: (nested within a for-loop to generate the appropriate amount of buttons)

    ActiveSheet.Buttons.Add(xpos, 462, width, height).Select
    Selection.Caption = [caption, long and irrelevant]
    Selection.name = "OptieBtn" & Str(count)
    Selection.OnAction = "Sheet7.SelectOpt"
    
    xpos = xpos + xspacing

    What I want is to somehow pass a parameter (count, in this case) to the 'SelectOpt' sub, so I know what option the user has selected (if it's somehow possible to get the object that triggered the sub, that would probably work too).

    Alternatively, it would be acceptable to set the "OnAction" property dynamically so that each button activates a different sub. I tried concatenating a number to the "OnAction" string, but excel doesn't seem to allow that.

    How can this be achieved?
    Last edited by Aeroren; 10-10-2010 at 05:43 PM. Reason: solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1