Solved

query active directory using vba

Posted on 2004-04-07
7
1,295 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office 2013 constant OST corruption 22 143
Help finding download OneNote 2016 or lates version 7 47
MS office 2010 activation 4 38
VBA name newly created sheet 4 20
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…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now