Hi All, new to vba coding and have been wrestling with an issue.
I have a large workbook with multiple worksheets. Each spreadsheet has information in it contained in option buttons (I think they are the Form Control type and not the ActiveX type). I am attempting to write code that extracts information from the optionbuttons.
In most of the worksheets, the option buttons are named consistently, and my code extracts the info I need when I reference the buttons by name. However, there are some sheets where the buttons randomly have different names, so I will need a macro to rename them (I think) so I can reference them properly.
Unfortunately, I haven't even gotten that far. Excel does not recognize any of the option buttons as being part of the Optionbuttons collection. Here is an example:
There is more to this code, but I shortened it to just the part I'm struggling with.
The line with "option button 17" is in there to prove that there is indeed an optionbutton on x. The msgbox displays "OptionButton" at that line, but nothing happens during the loop.
If I make myopt a shape and loop though .shapes instead of .optionbuttons, it finds all the group boxes, text boxes and other things on the sheet, but no option buttons.
Any help you can provide is appreciated. Thanks.
I have a large workbook with multiple worksheets. Each spreadsheet has information in it contained in option buttons (I think they are the Form Control type and not the ActiveX type). I am attempting to write code that extracts information from the optionbuttons.
In most of the worksheets, the option buttons are named consistently, and my code extracts the info I need when I reference the buttons by name. However, there are some sheets where the buttons randomly have different names, so I will need a macro to rename them (I think) so I can reference them properly.
Unfortunately, I haven't even gotten that far. Excel does not recognize any of the option buttons as being part of the Optionbuttons collection. Here is an example:
Code:
Sub OptionGet()
'set up worksheet and variables
Dim resultsheet As Worksheet, results As String, x As Worksheet, lastrow As Long, ResultsRange As Range, i As Integer, y As Long, myopt As optionbutton
results = "Results"
ActiveWorkbook.Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = results
Set resultsheet = Sheets(results)
lastrow = 1
'loop through worksheets
For Each x In ActiveWorkbook.Worksheets
If resultsheet.Cells(1, 2).Value = 0 Then
Set ResultsRange = resultsheet.Cells(1, 2)
Else: Set ResultsRange = resultsheet.Cells(lastrow, 2)
End If
'find option buttons
With x
'test that there is an option button in "x"
MsgBox (TypeName(.OptionButtons("Option Button 17")))
For Each myopt In .OptionButtons
MsgBox (myopt.Name & " " & TypeName(myopt) & " " & myopt.Type)
Next myopt
End With
Next x
End Sub
The line with "option button 17" is in there to prove that there is indeed an optionbutton on x. The msgbox displays "OptionButton" at that line, but nothing happens during the loop.
If I make myopt a shape and loop though .shapes instead of .optionbuttons, it finds all the group boxes, text boxes and other things on the sheet, but no option buttons.
Any help you can provide is appreciated. Thanks.