Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query active directory using vba

Posted on 2004-04-07
7
Medium Priority
?
1,312 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
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.

 
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 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