VBA Outlook Mailitem - not displaying all items

北慕城南 提交于 2019-12-12 00:46:12

问题


The below code does not pick up all of my emails in the Inbox.

The first item in my list box is an email from yesterday and the last 4/22/2014 - although my mailbox contains A LOT more than that.

Sub CheckEmail()

On Error Resume Next

Dim outApp As Outlook.Application
Dim outNs As Outlook.Namespace
Dim outFldr As Outlook.MAPIFolder
Dim outEmail As Outlook.MailItem

Dim p As Integer
p = 0

Set outApp = CreateObject("Outlook.Application")
Set outNs = outApp.GetNamespace("MAPI")
Set outFldr = outNs.GetDefaultFolder(olFolderInbox)

Dim searcht As String

'find search string

' do search

        For Each outEmail In outFldr.Items

            With fmShowsInboxEmails.ListBox1
                .AddItem outEmail.EntryID
                .List(p, 1) = outEmail.ReceivedTime
                .List(p, 2) = outEmail.Subject
                .List(p, 3) = outEmail.SenderEmailAddress
                .List(p, 4) = outEmail.Attachments.Count
            End With

            p = p + 1

        Next outEmail

On Error GoTo 0

Set outApp = Nothing
Set outNs = Nothing
Set outFldr = Nothing
Set outEmail = Nothing

fmShowsInboxEmails.Show

End Sub

回答1:


"type mismatch on the Next outEmail"

Items in the Inbox need not be mailitems.

Once you have Dim outEmail As Variant, test that outEmail is a mailitem before adding to the listbox.




回答2:


I think Outlook only counts items stored locally in the offline folder - so the messages stored on the server will not be a part of outFldr.Items



来源:https://stackoverflow.com/questions/24003325/vba-outlook-mailitem-not-displaying-all-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!