我想启动Outlook,然后Outlook应该只显示所有邮箱,这些邮箱也有未读的电子邮件。
目前,我的VBA脚本展开了我的所有邮箱文件夹/帐户。 但遗憾的是,这份清单太长了。
我正在寻找一种检查未读元素的方法。
我用简单的MsgBox
尝试了它,但是没有用。
Private Sub Application_Startup()
'Folder-Variable definieren
Dim objFolderIMAP01 As Outlook.Folder
Dim objFolderIMAP02 As Outlook.Folder
Dim objFolderIMAP03 As Outlook.Folder
'IMAP-Folder zuweisen (hier in Klammern mit Anführungszeichen den Namen der IMAP-Datendatei eintragen)
Set objFolderIMAP01 = Outlook.Session.Folders("MailBox1")
Set objFolderIMAP02 = Outlook.Session.Folders("MailBox2")
Set objFolderIMAP03 = Outlook.Session.Folders("MailBox3")
'Alle Unterordner selektieren (und damit aufklappen)
Call selectAllFolderRec(objFolderIMAP01)
Call selectAllFolderRec(objFolderIMAP02)
Call selectAllFolderRec(objFolderIMAP03)
'Posteingang als Startordnder auswählen
Call Outlook.ActiveExplorer.SelectFolder(objFolderIMAP01.Folders("Posteingang"))
Call Outlook.ActiveExplorer.SelectFolder(objFolderIMAP02.Folders("Posteingang"))
Call Outlook.ActiveExplorer.SelectFolder(objFolderIMAP03.Folders("Posteingang"))
'Info wenn mehr als 10 Emails ungelesen
If objFolderIMAP01.UnReadItemCount > 10 Then
MsgBox "Mailbox 1 ist voll!"
End If
If objFolderIMAP01.UnReadItemCount > 10 Then
MsgBox "Mailbox 2 ist voll!"
End If
If objFolderIMAP01.UnReadItemCount > 10 Then
MsgBox "Mailbox 3 ist voll!"
End If
End Sub
Sub selectAllFolderRec(objFolder As Outlook.Folder)
Dim lngCounter As Long
Dim bolSkipSelect As Boolean
bolSkipSelect = False
For lngCounter = 1 To objFolder.Folders.Count
If objFolder.Folders(lngCounter).Folders.Count > 0 And objFolder.Folders(lngCounter).Folders.UnReadItemCount > 10 Then
Call selectAllFolderRec(objFolder.Folders(lngCounter))
Else
If bolSkipSelect = False Then
Call Outlook.ActiveExplorer.SelectFolder(objFolder.Folders(lngCounter))
bolSkipSelect = True
End If
End If
Next lngCounter
End Sub
答案 0 :(得分:0)
名为“MailBox1”的文件夹没有邮件。
如果要在Mailbox1的收件箱中检查未读邮件,则必须指定objFolderIMAP01.Folders("Posteingang")
。
'Info wenn mehr als 10 Emails ungelesen
'Info if more than 10 mails unread
If objFolderIMAP01.Folders("Posteingang").UnReadItemCount > 10 Then
MsgBox "Inbox of Mailbox 1 is full! - Posteingang von Mailbox 1 ist voll!"
End If