values and variables question

R

R. Baas

Hello There.

I'm trying to make a template. When a user makes a new document based on
this template, it should automatically determine where this user is in the
Active Directory (using ADSI, to determine the user Initials, Surname and
location. Our OU's have the name of the departement the person is working
for.). This is not really the problem, I know a little ADSI.
I now have a few DocVariable fields which have to be filled with the
information from AD. Herein lies the problem: I can get the data from the AD
tree, but I can't seem to find out how to add the value to the DocVariable. I
do know something about declaring variables to use, so the code can be a lot
smaller, but I can't find the normal way to add the value to the variable.
Can someone please help me with this? Thanks in advance!!
 
J

Jezebel

"Variable" is ambiguous in Word VBA. It refers both to code variables -- the
things you have to declare in VBA code -- and Document variables, which are
values associated with a document, which you can display in the body of the
document using DocVariable fields.

I assume you mean document variables, which you set very simply --

ActiveDocument.Variables("Surname") = "Smith"

Unlike document properties, you don't need to add the variable explicitly
using the collection Add method.
 
R

R. Baas

Right, I'm sorry, didn't specify which variable.

Ok, so that's far more simple than I thought. Thank you!

This raises another question: when I read some information form an OU and
put this in a declared variable, can I just use this declared variable in the
line? So when I have a declared variable StrUserName, can I just do this:
ActiveDocument.Variables("Surname") = "Smith"
or do I have to use another method?

again, thanx in advance!
 
D

Doug Robbins

ActiveDocument.Variables("Surname").Value = "Smith"


--
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
 
R

R. Baas

I get the general idea now. This has been a great help!

Thanks Doug, the .Value was missing in my statement. It's working now!
 

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