Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Return selected option from a control

I am using Office 2003 on Windows XP.

I need to loop through the ActiveX controls (i.e. those from the Control
Toolbox) on the currently active sheet and IF the control is an OptionButton,
determine if it is the option chosen, if so, return the name of the control
in a variable.

Please note that there are other types of AX controls on the sheet, but only
one set of OptionButtons so far, so only one return value. Something like:

Dim oName as String
Dim octrls as OLEObjects
Dim octrl as OLEObject
For Each octrl in octrls
If octrl is an OptionButton then
If octrl is UserChoice then
oName = octrl.Name
End If
End If
Next

Can someone please post some example code?
Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Return selected option from a control

Dim oName as String
Dim octrls as OLEObjects
Dim octrl as OLEObject
Dim ob as MsForms.Optionbutton
set octrls = ActiveSheet.OleObjects
oName = ""
For Each octrl in octrls
If typeof octrl.Object is MSForms.OptionButton then
If octrl.Object.Value = True then
set ob = octrl.Object
oName = ob.Name
exit for
End If
End If
Next
if oName < "" then
msgbox oName & " was chosen"
else
msgbox "No choice made"
End if

--
Regards,
Tom Ogilvy


"XP" wrote in message
...
I am using Office 2003 on Windows XP.

I need to loop through the ActiveX controls (i.e. those from the Control
Toolbox) on the currently active sheet and IF the control is an

OptionButton,
determine if it is the option chosen, if so, return the name of the

control
in a variable.

Please note that there are other types of AX controls on the sheet, but

only
one set of OptionButtons so far, so only one return value. Something like:

Dim oName as String
Dim octrls as OLEObjects
Dim octrl as OLEObject
For Each octrl in octrls
If octrl is an OptionButton then
If octrl is UserChoice then
oName = octrl.Name
End If
End If
Next

Can someone please post some example code?
Thanks much in advance.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing drop down option after its been selected bbennett2 Excel Worksheet Functions 4 December 10th 08 01:40 AM
Option Button - multiple selected alanap Excel Worksheet Functions 1 April 17th 06 11:04 PM
Option buttons: How to get the selected option from a group? naddad Excel Programming 5 December 21st 05 05:09 PM
If option button not selected Hywel[_2_] Excel Programming 2 November 8th 05 09:32 AM
List Box - Option If wrongly selected Rob Excel Programming 2 August 24th 05 02:25 PM


All times are GMT +1. The time now is 07:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"