How to programmatically change option button value?

ameliiie

New Member
Joined
Feb 25, 2011
Messages
4
Hey there,

I'm writing a python plugin for a geo referencing program called QGIS where I want an Excel sheet to do all my calculations for me. For different data points I need to set certain input values into the spreadsheet (which was already written by someone else).
I'm fine setting the int values (using win32com.client) with

Code:
sheet.Cells(row, col).Value = value
For radio buttons I would expect it to work like so:
Code:
sheet.optionname.Value = True

But I get the error message:
AttributeError: '<WIN32COM.GEN_PY.MICROSOFT 0x232878608 at instance Library._Worksheet Object 12.0 Excel>' object has no attribute optionnameWhat are the options attributes of? How do I set their values?

If I can't firgure out any other way, I may have to use VB (but for this single task only, the rest of the code is pretty much finished in py). Is there a way to have this single function "outsourced" and run through the python main program in VB without actually integrating it into the workbook?

Thanks a lot for any help!

P.S. I know this is only 50% Excel/VB, but since I didn't get any help in other forums, I was hoping maybe here someone might know.
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

If the combobutton was added using the control toolbox then try this:

Code:
ActiveSheet.OLEObjects("OptionButton1").Object.Value = 1

No idea about using this from python though, not used python for several years now!
 
Upvote 0
No idea about using this from python though, not used python for several years now!
It's wokring great! Pyhton takes the command right in this form (obviously after importing win32com.client...).
Thank you so much, this really helped me a lot!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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