>1) I am following some tutorials on VBA specifically to learn the
>DocVariable fields. It says I should go to the File/Properties/Custom
[quoted text clipped - 19 lines]
>
>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
voip1234@mytrashmail.com - 09 Jan 2005 07:53 GMT
Thanks Jay, that worked...with a but....
it works, but the only way I get to see the DocVariable
fields in the document is by first selecting Print Preview.
After that, the correct variable is displayed. I suppose this
updates the field. What would the VBA code be so that
the macro updates the fields before it finishes executing.
(the fields are in the headers...dont know if that makes a
difference)
thanks for your help!!!! very much appreciated!!!
Jay Freedman - 09 Jan 2005 14:20 GMT
>Thanks Jay, that worked...with a but....
>it works, but the only way I get to see the DocVariable
[quoted text clipped - 5 lines]
>difference)
>thanks for your help!!!! very much appreciated!!!
That's a common problem. Among others, Peter Hewett has posted code to
update all the fields in the document. It's at
http://groups-beta.google.com/group/microsoft.public.word.vba.userforms/msg/12da
d96cad309e29
You're correct that going to Print Preview updates the fields (but
only if the "Update fields" option is checked in Tools > Options >
Print).
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
voip1234@mytrashmail.com - 09 Jan 2005 22:27 GMT
Thanks Jay, it worked perfectly.
Now on to making the userforms to some error checking.