Solved

query active directory using vba

Posted on 2004-04-07
7
1,298 Views
Last Modified: 2007-12-19
Hi,

I am trying to write a macro that will automatically create a signature for the end of a letter in MS Word (when I press the relavent button).

I want to query the current logged on user and with this username query my active directory for the following info:

Full Name
Organization Title and Department.
Telephone Number
Email
Fax Number

I Need to know:

How to query current logged on user
How to bind to AD
How to query the AD

Believe I need to be using ADSI, but the MSDN site is about 4000 miles over my head.

Thanks in advance.
0
Comment
Question by:unipol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:unipol
ID: 10775392
BTW I am using Windows 2003 Server and Word 2003 on an XP client.
0
 
LVL 81

Expert Comment

by:byundt
ID: 10775416
Hi unipol,
To get the name of the logged in user, you can use API function calls. John Walkenbach provides the code and describes the procedure: http://j-walk.com/ss/excel/tips/tip94.htm

Cheers!

Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 10780700
unipol,
I'm not the best person for a Word macro, but anyone attempting it will want to know where the following information is stored. Which file, what data structure, etc.
Brad

Full Name
Organization Title and Department.
Telephone Number
Email
Fax Number
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Expert Comment

by:Dave Brett
ID: 10781083
The logged on user name can be returned with

MsgBox Environ("USERNAME")

Cheers
Dave
0
 

Author Comment

by:unipol
ID: 10822726
Got there in the end.
Did not use the Username environmental variable, but got the distinguished name with ADSystemInfo
Thanks for the effort.



Sub Signature()

Dim objSysinfo As Object
Dim objUser As Object

Dim strUser As String 'Distinguished Name

Set objSysinfo = CreateObject("ADSystemInfo")
strUser = objSysinfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

Selection.TypeText Text:=objUser.get("Title")
Selection.TypeParagraph
Selection.TypeText Text:=objUser.get("department")
Selection.TypeParagraph
Selection.TypeText Text:=objUser.get("telephonenumber")
Selection.TypeParagraph
Selection.TypeText Text:=objUser.get("facsimileTelephoneNumber")
Selection.TypeParagraph
Selection.TypeText Text:=objUser.get("mail")

End Sub
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 10854880
PAQd, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question