Iterating through controls

S

Saira

I am trying to iterate through all option buttons in a document.
I am really struggling with finding how to do this.
I have installed the Word PIAs and thought I could do it this way, but I'm
not even getting off the ground.
Has anyone done this? Can anyone give me a snippet of code or point me in
the right direction to start with.

Thanks very much
Saira
 
J

Jezebel

Dim pFormField as Word.FormField
For each pFormField in ActiveDocument.FormFields
...
Next
 
J

Jean-Guy Marcil

Saira was telling us:
Saira nous racontait que :
I am trying to iterate through all option buttons in a document.
I am really struggling with finding how to do this.
I have installed the Word PIAs and thought I could do it this way,
but I'm not even getting off the ground.
Has anyone done this? Can anyone give me a snippet of code or point
me in the right direction to start with.

I'm assuming that these controls are ActiveX controls inserted with the
Control Toolbox.

'_______________________________________
Sub IterateOptionBUttons()

Dim myObj As Field
Dim ObjNames As String
Dim SourceDoc As Document

Set SourceDoc = ActiveDocument

For Each myObj In SourceDoc.Fields
With myObj
If Not InStr(1, .Code, "Forms.OptionButton.1") = 0 Then
ObjNames = ObjNames & .OLEFormat.Object.Name & Chr(13)
.OLEFormat.Object.Value = Not .OLEFormat.Object.Value
End If
End With
Next myObj

MsgBox ObjNames

End Sub
'_______________________________________

Of course, the Value statement is just to show you how to manipulate/use the
value of the option button. As is, this code will always make the last
option button in each group be equal to "True".

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cindy M.

Hi Saira,
I am trying to iterate through all option buttons in a document.
I am really struggling with finding how to do this.
I have installed the Word PIAs and thought I could do it this way, but I'm
not even getting off the ground.
Has anyone done this? Can anyone give me a snippet of code or point me in
the right direction to start with.
If you're doing this in C#, see the message thread with the following subject
line in the office.developer.automation newsgroup

C#: Reading a value of a checkbox created with the Control Toolbar

ActiveX checkboxes are basically the same kind of things as the Option
buttons. Note that you first have to determine whether the option buttons in
your document are in the Shapes or InlineShapes collection. The approach
Jean-Guy gives you here assumes they're InlineShapes (no text flow
formatting). The code Roman posts as his solution assumes the objects are
part of the Shapes collection.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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

Top