下面的代码不会收到我在收件箱中的所有电子邮件。
我列表框中的第一项是昨天和 2014 年 4 月 22 日最后一封电子邮件——尽管我的邮箱包含的远不止这些。
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