Solved

outlook email from active directory

Posted on 2015-01-06
7
166 Views
Last Modified: 2015-01-12
Hello All,

Is it possible via vba if a excel sheet has a list of outlook users in a column, then for each of those contacts, i can get their names and positions from active directory or outlook server?

Thanks
0
Comment
Question by:Rayne
[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
  • 4
  • 3
7 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 40533868
Assuming that by "outlook users" you mean a user name, then the answer is yes.  You can get the info from AD with something like this

Sub UpdateWorkbook()
    'On the next line, edit the path to your domain
    Const MY_DOMAIN = "LDAP://company.com"
    Dim excWks As Excel.Worksheet, adoCon As Object, adoRec As Object, lngRow As Long
    Set excWks = Application.ActiveSheet
    
    Set adoCon = CreateObject("ADODB.Connection")
    With adoCon
        .Provider = "ADsDSOObject"
        .CursorLocation = 3
        .Open "ADSI"
    End With
    
    For lngRow = 1 To excWks.UsedRange.Rows.Count
        Set adoRec = adoCon.Execute("SELECT sn,givenName,title FROM '" & MY_DOMAIN & "' Where objectClass='user' AND objectCategory='Person' AND samAccountName='" & excWks.Cells(lngRow, 1).Value & "'")
        If (Not adoRec.bof) And (Not adoRec.EOF) Then
            excWks.Cells(lngRow, 2) = adoRec.Fields("sn").Value
            excWks.Cells(lngRow, 3) = adoRec.Fields("givenName").Value
            excWks.Cells(lngRow, 4) = adoRec.Fields("title").Value
        End If
    Next

    adoRec.Close
    adoCon.Close
    Set adoRec = Nothing
    Set adoCon = Nothing
    Set excWks = Nothing
End Sub

Open in new window

0
 

Author Comment

by:Rayne
ID: 40533986
Hello BlueDevilFan,

I am getting an error when its executes
error5.bmp
0
 

Author Comment

by:Rayne
ID: 40533988
i gave  a sample existing user id like "ssamy"
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 76

Expert Comment

by:David Lee
ID: 40534062
Did you edit the MY_DOMAIN constant at the top of the script?
0
 

Author Comment

by:Rayne
ID: 40534110
yes I did to change it to my company..
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40534648
Then the domain you entered must not be correct.  I tested the code using my domain and it worked correctly.
0
 

Author Comment

by:Rayne
ID: 40545856
thank you bluedevilfan :)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
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 …
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

696 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