?
Solved

VBA Looking Up User in Global Address List

Posted on 2010-09-16
9
Medium Priority
?
8,398 Views
Last Modified: 2013-12-25
So I have the VBA code below, found via Google. References are as shown in the attached bitmap, all in Office 2007.

What I'd like to do is modify the line which dispalys the Global Address List to default to select a specific individual (e.g. I want to use this to look up people in the GAL)
Set orecip = oCDOSession.AddressBook(Nothing, txtCaption, True, True, 1, buttontext, "", "", 0)

when the thing opens. However, I can't find ANY documentation on the Namespace.AddressBook method. Any ideas what each of it's arguements represent, or where there is some documentation on this? (I understand args 2 and 6...)


Sub Main()
    Call Globaladdress("Access-Executive", "Address Book: Global Address List", "Add")
End Sub

Sub Globaladdress(fieldname, caption, buttontext)
    Dim oOutlookApplication As Outlook.Application
    On Error Resume Next
    
    If oOutlookApplication Is Nothing Then
        Err.Clear
        Set oOutlookApplication = CreateObject("Outlook.Application")
    Else
        Set oOutlookApplication = GetObject(, "Outlook.Application")
    End If
    
    Set oCDOSession = CreateObject("Mapi.Session")
    oCDOSession.Logon "", "", False, False, 0
    txtCaption = caption 'The title of the window, e.g. "Address Book: Global Address List"
    
    If Not Err Then
        Set orecip = oCDOSession.AddressBook(Nothing, txtCaption, True, True, 1, buttontext, "", "", 0)
    End If
    
    If Not Err Then
        Item.UserProperties.Find(fieldname).Value = orecip(1).Name
    End If
    
    oCDOSession.Logoff
    oCDOSession = Nothing
    oOutlookApplication = Nothing
End Sub

Open in new window

References.bmp
0
Comment
Question by:travisjbennett
[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
9 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 33694016
Hi, travisjbennett.

Forgetting about this code for a minute, what is it that you want to accomplish?  There may be a simpler way to do this.
0
 
LVL 1

Author Comment

by:travisjbennett
ID: 33694072
I already know how to use LDAP via VBA -- I'm just trying to learn the method to give end users a nice pretty recognizable dialog with all the user info in it -- a way to automate looking up someone in the GAL.
All I want to do is pre-select someone (their name highlighted for easy right clicking to properties) in the GAL.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33749105
Sorry, but I'm not clear on what you have in mind.  Outlook already has a means of searching the GAL and right-clicking to view the properties of an entry.  Are you proposing another means of doing the same thing?  If so, what's the advantage?  If not, then I'm not understanding your goal.
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 1

Author Comment

by:travisjbennett
ID: 33750033
Outlook has the abilities built in, sure...

... But Access does not.

A VBA solution would make it extensible across all of Microsoft Office.

I want to open a user properties form from Access, and add/remove people to lists within Access.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33750161
You can call Outlook's address book function from any Microsoft Office app using VBA.
0
 
LVL 1

Author Comment

by:travisjbennett
ID: 33750181
How?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1600 total points
ID: 33806293
Sorry to be slow.  Here's how.  Be sure to include a project reference to Outlook.
Sub ShowOutlookAddressBook()
    Dim olkApp As Outlook.Application, olkSes As Outlook.Namespace, olkSND As Outlook.SelectNamesDialog
    Set olkApp = GetObject(, "Outlook.Application")
    Set olkSes = olkApp.Session
    Set olkSND = olkSes.GetSelectNamesDialog
    With olkSND
        .AllowMultipleSelection = True
        .Display
        'The selections the user makes will be in the olkSND.Recipients collection'
    End With
    Set olkSND = Nothing
    Set olkSes = Nothing
    Set olkApp = Nothing
End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34740789
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
This video discusses moving either the default database or any database to a new volume.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 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