Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Control Toolbox Controls in Documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 10 Aug 2006 18:46 GMT
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
Jay Freedman - 11 Aug 2006 02:29 GMT
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.

>I am stumgling in the dark trying learn something to help a poster.
>
[quoted text clipped - 33 lines]
>Next
>End Sub
Greg Maxey - 11 Aug 2006 02:43 GMT
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?

Signature

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

> Hi Greg,
>
[quoted text clipped - 68 lines]
>> Next
>> End Sub
Jay Freedman - 11 Aug 2006 04:58 GMT
>Jay,
>
[quoted text clipped - 8 lines]
>
>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.
Greg Maxey - 11 Aug 2006 17:11 GMT
Thanks again Jay.  I think I understand it a bit better now.

> >Jay,
> >
[quoted text clipped - 39 lines]
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
Cindy M. - 11 Aug 2006 09:47 GMT
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
:-)
Greg Maxey - 11 Aug 2006 17:12 GMT
Cindy,

Thanks.  I will have a look at that.

> Hi Greg
>
[quoted text clipped - 13 lines]
> follow question or reply in the newsgroup and not by e-mail
> :-)

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.