如何:访问 Outlook 联系人

更新:2007 年 11 月

适用对象

本主题中的信息仅适用于指定的 Visual Studio Tools for Office 项目和 Microsoft Office 版本。

项目类型

  • 应用程序级项目

Microsoft Office 版本

  • Outlook 2003

  • Outlook 2007

有关更多信息,请参见按应用程序和项目类型提供的功能

此示例查找姓氏包含指定搜索字符串的所有联系人。

示例

Private Sub ThisAddIn_Startup(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Startup
    AccessContacts("Na")
End Sub

Private Sub AccessContacts(ByVal findLastName As String)
    Dim folderContacts As Outlook.MAPIFolder = Me.Application.ActiveExplorer() _
        .Session.GetDefaultFolder(Outlook.OlDefaultFolders _
        .olFolderContacts)
    Dim searchFolder As Outlook.Items = folderContacts.Items
    Dim counter As Integer = 0
    For Each foundContact As Outlook.ContactItem In searchFolder
        If foundContact.LastName.Contains(findLastName) Then
            foundContact.Display(False)
            counter = counter + 1
        End If
    Next
    MessageBox.Show("You have " & counter & _
        " contacts with last names that contain " _
        & findLastName & ".")
End Sub

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    AccessContacts("Na");
}

private void AccessContacts(string findLastName)
{
    Outlook.MAPIFolder folderContacts = this.Application.ActiveExplorer().Session.
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
    Outlook.Items searchFolder = folderContacts.Items;
    int counter = 0;
    foreach (Outlook.ContactItem foundContact in searchFolder)
    {
        if (foundContact.LastName.Contains(findLastName))
        {
            foundContact.Display(false);
            counter = counter + 1;
        }
    }
    MessageBox.Show("You have " + counter +
        " contacts with last names that contain "
        + findLastName + ".");
}

编译代码

此示例需要:

  • 在“联系人”文件夹中,姓氏包含字符串“Na”(例如,Tzipi Butnaru)的联系人。

请参见

任务

如何:向 Outlook 联系人添加项

如何:搜索特定联系人

如何:在联系人中搜索电子邮件地址

如何:删除 Outlook 联系人

概念

使用联系人项