Jay
Sat Jan 08 13:32:23 CST 2005
On 8 Jan 2005 00:42:30 -0800, "DG" <gkrawiec@hotmail.com> wrote:
>1) I am following some tutorials on VBA specifically to learn the
>DocVariable fields. It says I should go to the File/Properties/Custom
>dialog box and add the field there first. I go there and can type the
>name of the field, select the type and even type a value, but the ADD
>DELETE buttons are always grayed out. They stay gray even after
>populating the boxes. I tried a blank document, an old document,
>etc....same thing...tried closing opening word again...same thing.
>I am using Word 2003 on a public computer (I pay to access it), could
>this be a security setting in the computer? I was told that the
>computers are completely open and nothing is prohibited, so I doubt it
>might be anything like that. Any ideas?
>
>2) the reason I am looking into DocVariable is that I want to
>programmatically insert different Autotext into the headers (different
>one for each odd portrait, even portrait, odd landscape, even
>landscape). I am now able to differentiate portrait/landscape sections,
>insert different even odd autotext headers...I can now even get the
>info I need from the user using an inputbox, but now I have to place
>the info I get from the input box into a variable field in the autotext
>entries. From what I read, DocVariable is the way to go....am I right?
>Any other suggestions?
>
>thanks.
Well...
First off, Word documents can contain two different kinds of things,
document *properties* and document *variables*. They aren't
interchangeable.
Custom document properties can be inserted in the File > Properties >
Custom tab. I have no idea why you can't get that to work, although
public computers can get screwed up in a million unimaginable ways.
The same properties can be created through VBA instead, using the
ActiveDocument.CustomDocumentProperties.Add method. To display the
value of a document property in the document (including its header),
insert a {DOCPROPERTY} field containing the property's name.
Document variables must be created by VBA code; there is no dialog for
them. To do this, you use the ActiveDocument.Variables.Add method. To
display them in the document, insert a {DOCVARIABLE} field containing
the variable's name.
[Hint: If you use the Add method to try to define a variable that
already exists, VBA throws an error. A better method is simply to
assign it a value, like ActiveDocument.Variables("foo").Value = "bar".
If the variable doesn't exist yet, this statement creates it; if it
does exist, the statement changes the value.]
I'm trying to understand what you're doing. Am I correct that your
AutoText entries contain both plain text and fields, and you want the
fields to display the user's input? In that case, yes, I think
document variables are appropriate. However, I think you should look
into userforms (see, for example,
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm) instead
of individual input boxes. Once the userform has collected the user's
input, the code attached to the form can create the document
variables. There are advantages to this: the code can validate the
input (for example, to make sure the user hasn't left a required field
blank), and it's less annoying to fill out one form than to be
presented with a string of popups.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org