HOW TO:以程式設計方式存取 Outlook 連絡人
這個範例會找出姓氏含有指定之搜尋字串的所有連絡人。
**適用於:**本主題中的資訊適用於 Outlook 2013 和 Outlook 2010 的應用程式層級專案。如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能。
範例
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
MsgBox("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 + ".");
}
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 連絡人