Controls Collection + VBA

H

Hemant

Hi,

I have placed some controls (from View -> Toolbars -> Control Toolbox) on
the word form. I 'm restricted to use controls from this toolbox only. What i
have been asked is to have a button on a word form and when that button is
clicked, i must display using a msgbox, the name of the control, its caption
and some other properties of the control.

I have tried this but it is not helping me.

Dim fld As Field
dim fldCount as Integer
dim intIndex as Integer

for intIndex = 1 to ThisDocument.Fields.Count
Set fld = ThisDocument.Fields(intIndex)

If fld.Type = TextboxType Then
' show text box name and text
elseif fld.Type = CheckboxType then
' show checkbox name and checked state (T / F)
elseif ....(more controls)
End If
Next intIndex
 
P

Perry

Just got my mind off a solution posted by macropod, couple of threads up ...
*few*
The impressive ones, they resonate ...

Back to yr quest
Either you've coded incorrectly, or y're using the wrong fields.

If y're trying to loop through FormFields (View|Toolbars|Forms) then
yr code should do it.
If y're trying to loop through controls from the
toolbox(View|Toolbars|Control Toolbox) , the code is not
correct. These are ActiveX controls and do you really want to use them?
Anyhow, you can do somehting like:

Dim ils As InlineShape
For Each ils In ActiveDocument.InlineShapes
Select Case ils.OLEFormat.ClassType
Case "Forms.CheckBox.1"

Case "Forms.TextBox.1"
Case "Forms.Combobox.1"
case ...etc
End Select
Next

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
H

Helmut Weber

Hi everybody,
Dim ils As InlineShape
For Each ils In ActiveDocument.InlineShapes
Select Case ils.OLEFormat.ClassType
Case "Forms.CheckBox.1"
Case "Forms.TextBox.1"
Case "Forms.Combobox.1"
case ...etc
End Select
Next

yes, but it could be a shape as well.

Would be nice, if there was a kind of a graphical object,
representing both shapes and inlineshapes.

Maybe there is, but at least I haven't found out yet.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Perry

Would be nice, if there was a kind of a graphical object,
representing both shapes and inlineshapes.

Ah ah, uh uh, yep, I'm with you.
That would be very, very convenient, although when it comes to ActiveX
controls,
I don't like to use them in a Word document :-(

Excel "sheet" objects counter: ? Me.OLEObjects.Count
beautifully, by the way ...

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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