从Excel打开Outlook通讯簿 [英] Opening Outlook address book from Excel

查看:64
本文介绍了从Excel打开Outlook通讯簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Excel 2010和Outlook 2010(已打开)中使用VBA.

I'm using VBA in Excel 2010, with Outlook 2010 (already open).

我怎么写这样的一个子:

How could I write a sub such that:

1个Outlook通讯簿打开;
2用户选择一个联系人并单击确定";
3联系人的名字,姓氏和电子邮件地址存储在活动工作表的单元格中吗?

1 Outlook address book opens;
2 The user selects a contact and clicks ok;
3 The contact's first name, last name and email address are stored in cells of the active worksheet?

我尝试使用此方法未成功:

I tried with this method without success: SelectNamesDialog Object

我也不确定是否需要使用: Application.GetNamespace("MAPI")

Also I'm not sure if I need to use: Application.GetNamespace("MAPI")

推荐答案

以下是如何从GAL中选定联系人中获取所有详细信息的方法:

Here is how to get all the details from a selected contact in the GAL:

您需要打开全局地址列表(而不是联系人文件夹中的联系人),并按照

You need to open the Global Address List and not the contacts from the contact folder, and use an Outlook.ExchangeUser object as explained on this page: see last answer from David Zemens.

Private Sub cmdSetProjectMember1_Click()

    Dim olApp As Outlook.Application
    Dim oDialog As SelectNamesDialog
    Dim oGAL As AddressList
    Dim myAddrEntry As AddressEntry
    Dim exchUser As Outlook.ExchangeUser

    Dim AliasName As String
    Dim FirstName As String
    Dim LastName As String
    Dim EmailAddress As String

    Set olApp = GetObject(, "Outlook.Application")
    Set oDialog = olApp.Session.GetSelectNamesDialog
    Set oGAL = olApp.GetNamespace("MAPI").AddressLists("Global Address List")

    With oDialog
        .AllowMultipleSelection = False
        .InitialAddressList = oGAL
        .ShowOnlyInitialAddressList = True
        If .Display Then
            AliasName = oDialog.Recipients.Item(1).Name
            Set myAddrEntry = oGAL.AddressEntries(AliasName)
            Set exchUser = myAddrEntry.GetExchangeUser

            If Not exchUser Is Nothing Then
                FirstName = exchUser.FirstName
                LastName = exchUser.LastName
                EmailAddress = exchUser.PrimarySmtpAddress
                '...
                MsgBox "You selected contact: " & vbNewLine & _
                    "FirstName: " & FirstName & vbNewLine & _
                    "LastName:" & LastName & vbNewLine & _
                    "EmailAddress: " & EmailAddress
            End If
        End If
    End With
Set olApp = Nothing
Set oDialog = Nothing
Set oGAL = Nothing
Set myAddrEntry = Nothing
Set exchUser = Nothing
End Sub

这篇关于从Excel打开Outlook通讯簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆