[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1316
  • Last Modified:

query active directory using vba

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
unipol
Asked:
unipol
1 Solution
 
unipolAuthor Commented:
BTW I am using Windows 2003 Server and Word 2003 on an XP client.
0
 
byundtCommented:
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
 
byundtCommented:
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
Dave BrettCommented:
The logged on user name can be returned with

MsgBox Environ("USERNAME")

Cheers
Dave
0
 
unipolAuthor Commented:
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
 
GhostModCommented:
PAQd, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now