I have a VBA toolbar that i have been working on. It has two buttons, and near the end of the process, it calls a python script.
What I want to do is depending on which of the two buttons is clicked, a certain part of the python script will run, so I want to pass a value that is linked to the button which is then sent to the python script and run.
How do I do this?
Thanks
You can pass command line options to the python script, just like you can with other command line programs. Depending on which button was pressed, pass different switches to your program.
In your case, it may be simplest just to pass in one value on the command line depending on the button that was pressed and pick this from the
sys.argvvariable:(You could use a dict to look up methods but that may be too advanced, don’t know how comfortable you are with Python).
So, if you call this script with
python.exe H:\Report_v7.py foothefooClickedfunction will be called.If this is going to grow to more than just two buttons, I’d use the
optparsemodule to define your options and run different code paths depending on the options chosen.If you upgrade to Python 2.7, then use the new (better)
argparsemodule instead.