I am stumgling in the dark trying learn something to help a poster.

I have a Word document with some controls entered in the document using
the Control Toolbox. Specifically I have some options buttons named
Pass1 through Pass4.
I can run Sub Test1() to return the caption of Pass1. I can further
specifically (and I don't know if it is right or not) declare the
variable as a MSForms.OptionsButton and get the result using Sub
Test2(). What I can't figure out is how to cycle through each control
in the document and determine the caption.

It seems that there is no:

For each Ct in Me.Controls or Me.MSForms.OptionButtons or Me.Anything
that will work.

Can anyone help or confirm the quest is hopeless. Thanks.

Sub Test1()
Dim Ct
Set Ct = Me.Pass1
MsgBox Ct.Caption
End Sub

Sub Test2()
Dim Ct As MSForms.OptionButton
Set Ct = Me.Pass1
MsgBox Ct.Caption
End Sub

Sub Test3()
Dim Ct As MSForms.OptionButton
For Each Ct In Me (what would go here to get name of each OptionButton
in the form).
MsgBox Ct.Caption
Next
End Sub

Re: Control Toolbox Controls in Documents by Jay

Jay
Thu Aug 10 20:29:19 CDT 2006

Hi Greg,

It certainly wasn't easy to find this out -- it took some spelunking
in the Object Browser for likely bits of terms. :-b

The Control Toolbox controls are members of either the InlineShapes
collection or the Shapes collection, depending on whether they're
inline or floating, just like pictures.

For inline controls, use a loop like this:

Sub foo1()
Dim ctl As InlineShape
For Each ctl In ActiveDocument.InlineShapes
If ctl.Type = wdInlineShapeOLEControlObject Then
MsgBox ctl.OLEFormat.Object.Caption
End If
Next
End Sub

For floating controls, use a loop like this:

Sub foo2()
Dim ctl As Shape
For Each ctl In ActiveDocument.Shapes
If ctl.Type = msoOLEControlObject Then
MsgBox ctl.OLEFormat.Object.Caption
End If
Next
End Sub

If it's possible that both kinds are present, you have a heck of a
mess. I guess you could loop through the Paragraphs collection looking
for first one kind and then the other...

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On 10 Aug 2006 10:46:18 -0700, "Greg Maxey" <gmaxey@mvps.org> wrote:

>I am stumgling in the dark trying learn something to help a poster.
>
>I have a Word document with some controls entered in the document using
>the Control Toolbox. Specifically I have some options buttons named
>Pass1 through Pass4.
>I can run Sub Test1() to return the caption of Pass1. I can further
>specifically (and I don't know if it is right or not) declare the
>variable as a MSForms.OptionsButton and get the result using Sub
>Test2(). What I can't figure out is how to cycle through each control
>in the document and determine the caption.
>
>It seems that there is no:
>
>For each Ct in Me.Controls or Me.MSForms.OptionButtons or Me.Anything
>that will work.
>
>Can anyone help or confirm the quest is hopeless. Thanks.
>
>Sub Test1()
>Dim Ct
>Set Ct = Me.Pass1
>MsgBox Ct.Caption
>End Sub
>
>Sub Test2()
>Dim Ct As MSForms.OptionButton
>Set Ct = Me.Pass1
>MsgBox Ct.Caption
>End Sub
>
>Sub Test3()
>Dim Ct As MSForms.OptionButton
>For Each Ct In Me (what would go here to get name of each OptionButton
>in the form).
>MsgBox Ct.Caption
>Next
>End Sub

Re: Control Toolbox Controls in Documents by Greg

Greg
Thu Aug 10 20:43:40 CDT 2006

Jay,

Wow. Good detective work. I will play around with this some. Thanks. I
wonder why:

> Sub Test2()
> Dim Ct As MSForms.OptionButton
> Set Ct = Me.Pass1
> MsgBox Ct.Caption
> End Sub

Didn't throw some kind of error?


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jay Freedman wrote:
> Hi Greg,
>
> It certainly wasn't easy to find this out -- it took some spelunking
> in the Object Browser for likely bits of terms. :-b
>
> The Control Toolbox controls are members of either the InlineShapes
> collection or the Shapes collection, depending on whether they're
> inline or floating, just like pictures.
>
> For inline controls, use a loop like this:
>
> Sub foo1()
> Dim ctl As InlineShape
> For Each ctl In ActiveDocument.InlineShapes
> If ctl.Type = wdInlineShapeOLEControlObject Then
> MsgBox ctl.OLEFormat.Object.Caption
> End If
> Next
> End Sub
>
> For floating controls, use a loop like this:
>
> Sub foo2()
> Dim ctl As Shape
> For Each ctl In ActiveDocument.Shapes
> If ctl.Type = msoOLEControlObject Then
> MsgBox ctl.OLEFormat.Object.Caption
> End If
> Next
> End Sub
>
> If it's possible that both kinds are present, you have a heck of a
> mess. I guess you could loop through the Paragraphs collection looking
> for first one kind and then the other...
>
>
>> I am stumgling in the dark trying learn something to help a poster.
>>
>> I have a Word document with some controls entered in the document
>> using the Control Toolbox. Specifically I have some options buttons
>> named Pass1 through Pass4.
>> I can run Sub Test1() to return the caption of Pass1. I can further
>> specifically (and I don't know if it is right or not) declare the
>> variable as a MSForms.OptionsButton and get the result using Sub
>> Test2(). What I can't figure out is how to cycle through each
>> control in the document and determine the caption.
>>
>> It seems that there is no:
>>
>> For each Ct in Me.Controls or Me.MSForms.OptionButtons or
>> Me.Anything that will work.
>>
>> Can anyone help or confirm the quest is hopeless. Thanks.
>>
>> Sub Test1()
>> Dim Ct
>> Set Ct = Me.Pass1
>> MsgBox Ct.Caption
>> End Sub
>>
>> Sub Test2()
>> Dim Ct As MSForms.OptionButton
>> Set Ct = Me.Pass1
>> MsgBox Ct.Caption
>> End Sub
>>
>> Sub Test3()
>> Dim Ct As MSForms.OptionButton
>> For Each Ct In Me (what would go here to get name of each
>> OptionButton in the form).
>> MsgBox Ct.Caption
>> Next
>> End Sub



Re: Control Toolbox Controls in Documents by Jay

Jay
Thu Aug 10 22:58:50 CDT 2006

On Thu, 10 Aug 2006 21:43:40 -0400, "Greg Maxey"
<gmaxey@mvps.oSCARrOMEOgOLF> wrote:

>Jay,
>
>Wow. Good detective work. I will play around with this some. Thanks. I
>wonder why:
>
>> Sub Test2()
>> Dim Ct As MSForms.OptionButton
>> Set Ct = Me.Pass1
>> MsgBox Ct.Caption
>> End Sub
>
>Didn't throw some kind of error?

The control *is* an MSForms.OptionButton, so your code works
correctly. There's no error to throw. But, as you noted originally,
there is no collection whose members are OptionButtons, so you're
limited to working on one button and you need to know its name in
advance.

The Word object model (both the code of Word itself and the
underpinnings of VBA that represent it) pulls together a huge pile of
different kinds of objects into two collections, InlineShapes and
Shapes.

An individual member of either collection can come from any one of an
assortment of fundamental object types. For example, a Shape could
"really" be a picture, an AutoShape (or a set of grouped AutoShapes),
a text box, an embedded object from Excel or PowerPoint or some other
OLE server, one of these ActiveX controls, or just about anything else
that can be inserted in a document as a floating object. The .Type
property tells you which kind of object the Shape "really is".

My code says "if this thing is an OLE control object, then it has an
.OLEFormat property that represents its real nature, and inside that
is the actual .Object, and that has a .Caption property." It's the
buried .Object that "really is" an OptionButton.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Re: Control Toolbox Controls in Documents by Cindy

Cindy
Fri Aug 11 03:47:13 CDT 2006

Hi Greg

If you're going to explore these, you may want to read this
article, to avoid "re-inventing the wheel":

http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/dnword2k2/html/odc_activeX.asp

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
:-)


Re: Control Toolbox Controls in Documents by Greg

Greg
Fri Aug 11 11:11:32 CDT 2006

Thanks again Jay. I think I understand it a bit better now.


Jay Freedman wrote:
> On Thu, 10 Aug 2006 21:43:40 -0400, "Greg Maxey"
> <gmaxey@mvps.oSCARrOMEOgOLF> wrote:
>
> >Jay,
> >
> >Wow. Good detective work. I will play around with this some. Thanks. I
> >wonder why:
> >
> >> Sub Test2()
> >> Dim Ct As MSForms.OptionButton
> >> Set Ct = Me.Pass1
> >> MsgBox Ct.Caption
> >> End Sub
> >
> >Didn't throw some kind of error?
>
> The control *is* an MSForms.OptionButton, so your code works
> correctly. There's no error to throw. But, as you noted originally,
> there is no collection whose members are OptionButtons, so you're
> limited to working on one button and you need to know its name in
> advance.
>
> The Word object model (both the code of Word itself and the
> underpinnings of VBA that represent it) pulls together a huge pile of
> different kinds of objects into two collections, InlineShapes and
> Shapes.
>
> An individual member of either collection can come from any one of an
> assortment of fundamental object types. For example, a Shape could
> "really" be a picture, an AutoShape (or a set of grouped AutoShapes),
> a text box, an embedded object from Excel or PowerPoint or some other
> OLE server, one of these ActiveX controls, or just about anything else
> that can be inserted in a document as a floating object. The .Type
> property tells you which kind of object the Shape "really is".
>
> My code says "if this thing is an OLE control object, then it has an
> .OLEFormat property that represents its real nature, and inside that
> is the actual .Object, and that has a .Caption property." It's the
> buried .Object that "really is" an OptionButton.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.


Re: Control Toolbox Controls in Documents by Greg

Greg
Fri Aug 11 11:12:00 CDT 2006

Cindy,

Thanks. I will have a look at that.


Cindy M. wrote:
> Hi Greg
>
> If you're going to explore these, you may want to read this
> article, to avoid "re-inventing the wheel":
>
> http://msdn.microsoft.com/library/default.asp?url=/library/
> en-us/dnword2k2/html/odc_activeX.asp
>
> 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
> :-)