Avatar of Bernard Thouin
Bernard Thouin
Flag for Switzerland asked on

How to loop with VBA on all controls placed in a Word doc ?

Hi

I'm working on a Word template with controls, which I chose from the Control Toolbox (NOT from the "Forms" toolbar). It all works well until I try, in a kind of checking routine, to loop through all controls in the document creted through the template.

I can refer, in the VBA code, to single controls in the document with "Me.<Control name>", but I can't, for the life of me, find the syntax to go through all controls (to check their contents) in a generic loop.

I've tried to loop on Fields and FormFields, but I don't get what I want. The only thing I can find out is that I have 42 "fields" (which are my controls, in fact) and their type (combobox, textbox, listbox, ..), but I am unable to find how to get the controls' name and content in a generic "For next" loop. As I can't believe that this is not possible, I'm asking you for help :-)

Bernard
Microsoft Word

Avatar of undefined
Last Comment
Bernard Thouin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
GrahamSkan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bernard Thouin

ASKER
Hi

Brilliant ! Works like a breeze, thanks a lot. I would never have guessed that these controls were ActiveX, and even less that they are to be searched as inline shapes !

>>It has led users to think of a word document as a reasonable substitute for a Windows interactive form<<
I fully agree. The irony is, I HAVE already developed such a complete and sophisticated form in an Access front-end GUI, but my "clients" think that it'll be too complicated for the users... :-((
That's why I'm trying out the Word route. Is using Excel any better in that area ?

Two more small questions then (you get the points anyway):
- Is it a bug or a feature that, when one clicks in such an ActiveX control in Word and starts typing, the first caracter typed is NOT showing up, but all the following typed characters are OK ? To avoid this, I have to click twice in a control, then it doesn't "swallow" the first character !
- Is it a bug or a feature of ActiveX controls in Word that one cannot move from control to next control with either Tab or Return ? The cursor just doesn't move at all and stays in the field, one has to click in the next control. Very annoying

Thanks for your answers
Regards
Bernard
GrahamSkan

The are held in Inline shapes by default. They can be formatted to be 'floating', they would then be in the Shapes collection, which explains the second loop.

As with form fields, ActiveX controls work best when the document is protected for forms. The tab does work then.

I can't reproduce the first symptom, with or without forms protection (Word 2003).
Bernard Thouin

ASKER
Ah, I'll try protecting the doc, then.

Should I rather choose Excel to do the same thing ? Is it better ?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck