Getting value of an activeX option button

nemmi69

Well-known Member
Joined
Mar 15, 2012
Messages
938
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi,

I am using the following code
Code:
Sub WhichOption()    For Each objX In ActiveSheet.OLEObjects
        If objX.Enabled = True And objX.Visible = True And TypeName(objX.Object) = "OptionButton" Then
            If objX.Control.Value = True Then
                MsgBox "Name = " & objX.Name & "  Typ = " & TypeName(objX.Object) & " is selected"
                Exit For
            End If
        End If
    Next objX


End Sub

The line "objX.Control.Value = True" returns the error "Run-time error '438': Object doesn't support this property or method."

Any ideas?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,
try this update to your code

Code:
Sub WhichOption()
    Dim objX As OLEObject
    For Each objX In ActiveSheet.OLEObjects
        If TypeName(objX.Object) = "OptionButton" Then
            If objX.Enabled = True And objX.Visible = True Then
                If objX.Object.Value Then
                    MsgBox "Name = " & objX.Name & "  Typ = " & TypeName(objX.Object) & " is selected"
                    Exit For
                End If
            End If
        End If
    Next objX
End Sub

Dave
 
Upvote 0
Hi,
try this update to your code

Code:
Sub WhichOption()
    Dim objX As OLEObject
    For Each objX In ActiveSheet.OLEObjects
        If TypeName(objX.Object) = "OptionButton" Then
            If objX.Enabled = True And objX.Visible = True Then
                If objX.Object.Value Then
                    MsgBox "Name = " & objX.Name & "  Typ = " & TypeName(objX.Object) & " is selected"
                    Exit For
                End If
            End If
        End If
    Next objX
End Sub

Dave


Cheers Dave, works a treat! Any guesses what tripped it up? I was checking I was looking at an option button.
 
Upvote 0
Code:
Sub WhichOption()    For Each objX In ActiveSheet.OLEObjects
        If objX.Enabled = True And objX.Visible = True And TypeName(objX.Object) = "OptionButton" Then
            If objX.[B][COLOR="#FF0000"]Control[/COLOR][/B].Value = True Then
                MsgBox "Name = " & objX.Name & "  Typ = " & TypeName(objX.Object) & " is selected"
                Exit For
            End If
        End If
    Next objX
End Sub

The line "objX.Control.Value = True" returns the error "Run-time error '438': Object doesn't support this property or method."

Any ideas?
Change the red highlighted text to Object instead of Control and it should then work.
 
Upvote 0
Cheers Dave, works a treat! Any guesses what tripped it up? I was checking I was looking at an option button.


This line

Rich (BB code):
If objX.Control.Value = True Then


You were trying to use a property which is not available to the object.

and whilst this line may have worked

Rich (BB code):
If objX.Enabled = True And objX.Visible = True And TypeName(objX.Object) = "OptionButton" Then

personally, I prefer to test for the object I am working with first & then proceed with other tests.

Rich (BB code):
 If TypeName(objX.Object) = "OptionButton" Then
         'do other tests etc
  End If

hence my alteration - but if it was working for you, then your choice

Also, always better if you declare your variables with the appropriate data type.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,445
Messages
6,172,176
Members
452,446
Latest member
walkman99

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