showing Active Directory fields within MS Word

G

Grant Mantle

Hello,

Me, MS Word and coding are trouble at the best of time. I have a
request and am hoping you might be able to help me out.
I am wanting to suck out some data from our Active Directory and put in
to word if possible.

QUESTION 1: When person logs on to a workstation within the domain;
fields such as username, full name and email properties are attached
right?? - I hope so...

QUESTION 2: How does one get the fields (i.e. email address, username
and fullname) on to a word document? - the reason I ask is because I
have been assigned the task to create a template so the user just has
to type the message within the template and ideally not have to fill in
any particulars regarding to Full Name, email address etc...

QUESTION 3: Am I going about this all the wrong way? - is there an
alternative?

Many thanks in advance,

Grant
 
J

Jay Freedman

Hello,

Me, MS Word and coding are trouble at the best of time. I have a
request and am hoping you might be able to help me out.
I am wanting to suck out some data from our Active Directory and put in
to word if possible.

QUESTION 1: When person logs on to a workstation within the domain;
fields such as username, full name and email properties are attached
right?? - I hope so...

Not exactly, but the effect is the same. You can get the login name of
the current user by calling a function in the operating system of the
local machine. The code is at
http://www.word.mvps.org/FAQs/MacrosVBA/GetCurUserName.htm. For all
the other stuff, you have to contact the Active Directory, using
something called LDAP (Lightweight Directory Access Protocol). To do
this you write code that uses Active Directory Service Interfaces
(ADSI).

You can do this stuff from inside a VBA macro in Word. When you start
chasing down the documentation, most of the examples will be in
VBScript, but you can usually just paste it into a VBA macro and it
works. The main difference is that you don't use WScript.Echo for
output -- if you want to see output, replace WScript.Echo with
Debug.Print and open the Immediate Window of the VBA editor.
QUESTION 2: How does one get the fields (i.e. email address, username
and fullname) on to a word document? - the reason I ask is because I
have been assigned the task to create a template so the user just has
to type the message within the template and ideally not have to fill in
any particulars regarding to Full Name, email address etc...

There's an ADSI primer starting at
http://www.microsoft.com/technet/scriptcenter/guide/sas_ads_overview.mspx?mfr=true
that will show you, in particular, how to read properties of ADSI
objects. You'll need to know the full name of the domain that contains
the Active Directory; the primer's examples use the made-up domain
na.fabrikam.com.
QUESTION 3: Am I going about this all the wrong way? - is there an
alternative?

No alternative unless you want to write your own directory service
from scratch. :)
Many thanks in advance,

Grant

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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