MS Word Option Button Collection
Hi,
I am trying to use option buttons from the control toolbox in a word document.
I have set the groupname and they work fine but....
I then need to loop through the option button values in the group and I can not work out how to create the array or collection - I have tried the shapes property and the inlineshapes property of the active document but they have not worked.
I need code a bit alike below:
dim optBtn as msforms.optionbutton
for each optbtn in activedocument.?
msgbox optBtn.value
next optBtn
I can not work out what should be where the? are
Please help
Many thanks
[681 byte] By [
Ness22] at [2008-2-27]
Per one of our support engineers... try this code:
======
Dim optBtn As Control
For Each optBtn In Me.Controls
If TypeName(optBtn) = "OptionButton" Then
If optBtn.GroupName = "test" Then
MsgBox optBtn.Value
End If
End If
Next optBtn
======
I hope this helps,
-brenda (ISV Buddy Team)
The code in the first response only works if the controls are on a userform. In your case, the controls are directly on the document. Assuming your controls are all in the main document (as opposed to in headers/footers, footnotes/endnotest, or textboxes), and assuming they are all inline and not floating, then the following code should work:
Dim oShape As Word.InlineShape For Each oShape In ActiveDocument.InlineShapes
If oShape.OLEFormat.ProgID = "Forms.OptionButton.1" Then
MsgBox oShape.OLEFormat.Object.Value
End If
Next
Michael Herzfeld
Office Programmability Test Team