How to get every conytols

C

Cesarini

Hi Guys,

I'm working on Word 2007 and creating a form input user. I'm doing this for
a user that have Office 2003, so I have a compatibility mode template
document. It also include VBA code. What i need to do is to read every
existing text control. Theses controls are ActiveX.

I always have used:

For Each xControl In Controls
If TypeOf xControl Is TextBox Then
xControl.value=""
End If
Next xControl

But now in Word 2007 in compatibility mode I do not know how to do it,
becuase there is not "Controls" in the ActiveDocument.

Can any one help me about it? I will appreciate it
 
F

Fumei2 via OfficeKB.com

If these are ActiveX controls (inserted with the Controls toolbar) then they
are InlineShapes.

Sub AllTextBoxControls()
Dim ctl As InlineShape
For Each ctl In ActiveDocument.InlineShapes
If ctl.OLEFormat.ClassType = "Forms.TextBox.1" Then
MsgBox ctl.OLEFormat.Object.Value
End If
Next
End Sub

The above displays the text content of all ActiveX textboxes.

If what you want to do (apparently) is to make all the textboxes = "", then...


Sub AllTextBoxControls()
Dim ctl As InlineShape
For Each ctl In ActiveDocument.InlineShapes
If ctl.OLEFormat.ClassType = "Forms.TextBox.1" Then
ctl.OLEFormat.Object.Value = ""
End If
Next
End Sub

Gerry
 
C

Cesarini

Hi again Gerry,

Everything work just fine. Thanks, it was a helpful.

Just one doubt. Once i finish and take the template to he computer that has
the 2003 version, will it work?

I ask you because I'm not sure if the code will be recognized by that
version.

Just a Question. :)

And Thanks again,

Regards
 
D

Doug Robbins - Word MVP

It should be OK.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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