Solved

query active directory using vba

Posted on 2004-04-07
7
1,291 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 80

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 80

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Perhaps more familiar to developers who primarily use VBScript than to developers who tend to work only with Microsoft Office and Visual Basic for Applications (VBA), the Dictionary is a powerful and versatile class, and is useful …
How many times recently have you prepared a presentation or emailed a document to a client and you have found that they have older versions of MS Office and they can not open the file you have prepared.  Although most visitors to this site are exper…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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 …

759 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

19 Experts available now in Live!

Get 1:1 Help Now