how to access a value from excel option button using visual basic?

  • Thread starter Thread starter henry
  • Start date Start date
H

henry

Hi,
my name is henry. I want to ask how to access a value in Excel option button
which is using xlformcontrol.xloptionbutton
which the value i want to show in textbox as information.

i've coding :
msgbox excel.xlformcontrol.xloptionbutton
and it displayed number 7 which the const of xloptionbutton
what i want is the value inside the optionbutton not the const.

does anyone know the answer?
thank's in advance
 
Msgbox Optionbutton1.Value

But it will show True or False, that is set or not.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi Henry,

What you are checking is just the value of the constant that XL uses to
identify the type of shape. For more search XL VBA help for
xlformcontrol and you will be led to the 'FormControlType Property'
page.

What you want to do is check the caption of the option button that the
user selected. Assuming you put multiple option buttons within a group
box in a worksheet, XL will ensure that only one of the option buttons
is selected at any given time. Then, you can use code like:

Dim i As Integer
With ActiveSheet
For i = 1 To .OptionButtons.Count
If .OptionButtons(i).Value = 1 Then
.Labels(1).Caption = .OptionButtons(i).Caption
End If
Next i
End With

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top