1
我想啓動Outlook,那麼Outlook應該只顯示所有郵箱,其中也有未讀郵件。Outlook 2010 - VBA MsgBox如果超過10個未讀元素郵件
此刻,我的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
「不工作」是什麼意思 - 錯誤信息,錯誤的結果,什麼都沒有發生? – June7
我有點困惑,所以你想打開Outlook,只看到有未讀項目的帳戶?然後什麼? – 0m3r
我試過這個:'If objFolderIMAP01.UnReadItemCount> 10 Then MsgBox「Mailbox」&objFolderIMAP01&「ist voll!」 &「(」&objFolderIMAP01.UnReadItemCount&「)」 End If'但它總是計數0個未讀項目。 –