Tritt ein, wenn mindestens eine neue Nachricht im Posteingang eingegangen ist. Dieses Ereignis ist in VBScript nicht verfügbar.
Sub Objekt_NewMail()
Objekt Ein Ausdruck, der den Wert eines Application-Objekts annimmt.
In diesem Beispiel wird der Ordner Posteingang angezeigt, wenn eine oder mehrere neue Nachrichten eingegangen sind. Der Beispielcode muss sich in einem Klassenmodul befinden, und die Initialize_handler
-Routine muss aufgerufen werden, bevor Microsoft Outlook die Ereignisprozedur aufrufen kann.
Dim WithEvents myOlApp As Outlook.Application
Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.application")
End Sub
Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
End Sub