Gewusst wie: Programmgesteuertes Zugreifen auf Outlook-Kontakte
In diesem Beispiel werden alle Kontakte gesucht, deren Nachname eine angegebene Suchzeichenfolge enthält.
Betrifft: Die Informationen in diesem Thema betreffen Projekte auf Anwendungsebene für Outlook 2013 und Outlook 2010. Weitere Informationen finden Sie unter Verfügbare Funktionen nach Office-Anwendung und Projekttyp.
Beispiel
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 + ".");
}
Kompilieren des Codes
Dieses Beispiel setzt Folgendes voraus:
- Kontakte im Kontakteordner, deren Nachname die Zeichenfolge "Na" enthält (z. B. Tzipi Butnaru).
Siehe auch
Aufgaben
Gewusst wie: Programmgesteuertes Hinzufügen eines Eintrags zu Outlook-Kontakten
Gewusst wie: Programmgesteuertes Suchen eines bestimmten Kontakts
Gewusst wie: Programmgesteuerte Suche einer E-Mail-Adresse in den Kontakten
Gewusst wie: Programmgesteuertes Löschen von Outlook-Kontakten