Solved

Enabling and disabling option buttons in Excel using macros

Posted on 2003-11-04
6
998 Views
Last Modified: 2010-04-17
Hi!
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.

Luk.
0
Comment
Question by:lhdarg
  • 2
  • 2
  • 2
6 Comments
 
LVL 69

Expert Comment

by:Callandor
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.
0
 
LVL 9

Accepted Solution

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

Author Comment

by:lhdarg
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?

Thanks!

Luk.
0
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.

 

Author Comment

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

The sentence

Worksheets(name).OptionButton.Enabled = True

works!!

Many thanks.

Luk
0
 
LVL 69

Expert Comment

by:Callandor
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.
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9698880
Glad could help!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.

830 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