Add user-replaceable text with VBA

M

Mike Litzkow

Just about every template I look at contains some text "fields" which are
intended to be replaced by the user. For example, a fax template would
contain fields like "[Click here and type name]" and "[Click here and type
subject of fax]". These text fields are handled speically, as the user only
has to click once to select the whole phrase for replacement. This is a nice
property, which users seem to expect in templates. I want to be able to add
such fields to my own document, but I don't know how many such "place holder"
fields I will need ahead of time. I want to add these fields based on a menu
or toolbar click. My question is how can I create a field like this using VBA
and the Word or Office document object model, (not how to attach that code to
a menu or toolbar). I have been searching word help, MSDN docs, etc, but I
just don't know what to call a field that acts in this way, and cannot find
documentation on how to create such a field using VBA.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWlrZSBMaXR6a293?=,

Usually, these are MacroButton fields that reference a non-existant macro (IOW,
you supply a macro name, but no macro of that name needs to be available).

Look up MacroButton field in Word's Help files to understand the syntax

Use the Fields.Add method to insert the field at the target range.

Note: the "caption text" displayed by the field will NOT wrap (break over a
line); it must all display on one line.
Just about every template I look at contains some text "fields" which are
intended to be replaced by the user. For example, a fax template would
contain fields like "[Click here and type name]" and "[Click here and type
subject of fax]". These text fields are handled speically, as the user only
has to click once to select the whole phrase for replacement. This is a nice
property, which users seem to expect in templates. I want to be able to add
such fields to my own document, but I don't know how many such "place holder"
fields I will need ahead of time. I want to add these fields based on a menu
or toolbar click. My question is how can I create a field like this using VBA
and the Word or Office document object model, (not how to attach that code to
a menu or toolbar). I have been searching word help, MSDN docs, etc, but I
just don't know what to call a field that acts in this way, and cannot find
documentation on how to create such a field using VBA.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 

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