Gruppe
Extern
Bereich
Outlook
Thema
Prüfen, ob ein Name im Outlook-Adressbuch existiert
Problem
Im Outlook-Adressbuch soll der in Zelle B1 eingetragene Name gesucht und das Ergebnis der Suche in einer MessageBox angezeigt werden.
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: Modul1
Sub NameExists()
Dim oOL As Object
Dim oAdr As Object
Dim oEntry As Object
Dim iCounter As Integer
Dim bln As Boolean
bln = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Set oOL = CreateObject("Outlook.Application")
Set oAdr = oOL.Session.AddressLists("Kontakte")
For Each oEntry In oAdr.AddressEntries
If iCounter Mod 10 = 0 Then
Application.StatusBar = _
"Prüfe Adresse Nr. " & iCounter & "..."
End If
If Range("B1").Value = oEntry.Name Then
MsgBox "Adresse wurden gefunden!"
GoTo FINISH
End If
iCounter = iCounter + 1
Next oEntry
MsgBox "Name wurde nicht gefunden!"
FINISH:
Set oOL = Nothing
Application.StatusBar = False
Application.DisplayStatusBar = bln
End Sub