Enabling and disabling option buttons in Excel using macros

Posted on 2003-11-04
Medium Priority
Last Modified: 2010-04-17
I'm working with an excel 2002 file and I have a combo box and some option buttons. Depending on the choice in the combo I have to enable/disable some of the option buttons.
I began programming the macro for the OnChange event of the combo but I need to know which is the piece of code to do that, because the sentence

 Worksheets(name).OptionButton1.Enable = True (Or false)

doesn´t work.

I also think about hide the rows containing the option buttons I have to disable but the problem is that the rows dissapeared but the objects (I mean the option buttons) stay together in a row so that's why I'm trying to disable them.

Any solution or another suggestion will be good!

Thanks in advance.

Question by:lhdarg
  • 2
  • 2
  • 2
LVL 69

Expert Comment

ID: 9680320
You have to point to the combo box in order to change properties of buttons within it, so your code should look like: Worksheets(name).ComboBox(myCombo).OptionButton1.Enable = True (Or false)

If your buttons are not on the combo box, your code should work.  I would use the debugger and singlestep through the call to see what it's doing.

Accepted Solution

bhagyesht earned 225 total points
ID: 9684777
use option buttons from the control toolbox instead of option buttons from the form tool box

Author Comment

ID: 9687532
Callandor: I noticed that I was using the wrong object so I inserted the control toolbox option button so now I have the prooperty panel.

Now I'm trying to change the state  (from enable to disable or the other way round) but I don't know how to do it.
The option button is an object separated from the combo box. What I need is to turn to enable (or disable) some option buttons in case the item selected in the combo is something specific.

I tried with

Worksheets(name).OptionButton.Enable = True

but it says the method or property is nos available for that object.

Any solution?


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9687736
Sorry, I was using "enable" instead of "enabled".

The sentence

Worksheets(name).OptionButton.Enabled = True


Many thanks.

LVL 69

Expert Comment

ID: 9687976
I tried recording a macro while selecting a button and altering its properties - I could not capture anything I did after selecting the button.  Apparently, not all objects support dynamic change of properties, so it looks like you need to work around the limitation.  You can change the value in a cell in the spreadsheet, depending on what is selected in the combo box, and then when you press the button, test the value in the cell and decide what to do.  Not very elegant, but VBA is limiting what you can do here.

Expert Comment

ID: 9698880
Glad could help!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question