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 / March 2006

Tip: Looking for answers? Try searching our database.

Controls Collections for Active Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Weste - 31 Mar 2006 13:08 GMT
I am trying to loop thru all the controls in my Word document - text boxes
and combo boxes.  I am not using form fields.  Is there a collection I can
use to do this.  The controls collection only seems to be available with user
forms and not documents.  Thanks for your help!

Weste
Jonathan West - 31 Mar 2006 13:23 GMT
>I am trying to loop thru all the controls in my Word document - text boxes
> and combo boxes.  I am not using form fields.  Is there a collection I can
[quoted text clipped - 3 lines]
>
> Weste

You need to look at the CommandBars collection and the Controls collection
of each Commandbar object.

When doing this, you need to be very careful that you set the
CustomizationContext property correctly. The CustomizationContext defines in
what document, template or add-in the toolbars and buttons are stored. if
you make any change to a button, the change will be stored in the file
specified as the current CustomizationContext.

This is a notoriously tricky part of Word programming. Proceed with caution
and take regular backups.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Tony Jollans - 31 Mar 2006 13:26 GMT
Either (or probably both of) the Shapes and the InlineShapes collections.

--
Enjoy,
Tony

> I am trying to loop thru all the controls in my Word document - text boxes
> and combo boxes.  I am not using form fields.  Is there a collection I can
> use to do this.  The controls collection only seems to be available with user
> forms and not documents.  Thanks for your help!
>
> Weste
Helmut Weber - 31 Mar 2006 20:29 GMT
Hi Weste,

to the best of my limited knowledge,
controls form the control toolbox are
either shapes or inlineshapes.

So you might have to loop through all shapes
and inlineshapes and check their type.

Inlineshape controls are of type 5 (= wdInlineShapeOLEControlObject).

Here is an example for inlineshapes, in the doc's mainstory.

Sub test400()
Dim iShp As InlineShape
For Each iShp In ActiveDocument.InlineShapes
  If iShp.Type = wdInlineShapeOLEControlObject Then
     If iShp.OLEFormat.ClassType = "Forms.TextBox.1" Then
        MsgBox "Control Textbox"
     End If
     If iShp.OLEFormat.ClassType = "Forms.ComboBox.1" Then
        MsgBox "Control Combobox"
     End If
  End If
Next
End Sub

Note, that the comparison is case sensitive,
so "Forms.Textbox.1" won't work,
whereas "Forms.TextBox.1" does.

With shapes, which have to be converted from
inlineshapes to shapes programmatically beforehand,
things seem to be different, as they are
of type msoOLEControlObject,
which means, they are part of Office, not of Word.

Sub test401()
Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
  If oShp.Type = msoOLEControlObject Then
     MsgBox oShp.OLEFormat.ClassType
  End If
Next
End Sub

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


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.