PDA

View Full Version : Can a command button pass variables to a program?



RonMcK
05-31-2011, 10:42 AM
Hi, All,

I have a program that I want my users to start/invoke by pressing a command button on the Excel worksheet. Actually, there will be two such buttons and the two programs are slight variations of each other.

Can I have the command button pass in variable values so I only need to use and maintain one "master" program? The program, using those variables and conditional logic, will then perform the selected processes.

Or, do I need to build a couple of small "pre-programs" to create and set the variables and their values before passing them to the "master" program?

Or, is there a better way to do this?

And, will this work on XL2004 on my Mac (in addition to on my PC)?

Thanks,

Chabu
05-31-2011, 03:18 PM
I would provide an input/control sheet to the user (or a form if you want) that allows your user to input/select the values that drive your master program.

mikerickson
05-31-2011, 04:22 PM
I just (re)discovered something pretty cool.

If you have a macro that takes an argument, like
Sub Test(aNum As Double)
MsgBox aNum + 1
End Sub
You can call it, and pass an argument to it, from the Macro dialog box.

Invoke the Macros dialog. (you won't see Test in the list of macros)
Type 'Test 12' (including the apostrophes) into the Macro Name text box
A MsgBox with 13 will appear.

Similarly, you can assign a (forms) button to the macro 'Test 4'.
Pressing the button will cause a MsgBox to show 5.

You can pass arguments to a sub with a button, but only a "hard coded" argument.

RonMcK
06-01-2011, 11:39 AM
Chabu,

Thanks, I'll look at that possibility. The critical point to any solution is that it run on XL 2004 on our Macs.

Mik,

Thanks, that may be what I need; the variable would be a fixed value for each user. At the moment, I'm leaning towards your earlier suggestion of using the button_click event.

Thanks,