共用方式為


HOW TO:存取 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) 的連絡人。

請參閱

工作

HOW TO:將項目加入至 Outlook 連絡人

HOW TO:搜尋特定的連絡人

HOW TO:在連絡人中搜尋電子郵件地址

HOW TO:刪除 Outlook 連絡人

概念

使用連絡人項目