VBA Outlook Mailitem - 不显示所有项目 [英] VBA Outlook Mailitem - not displaying all items
本文介绍了VBA Outlook Mailitem - 不显示所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码不会收到收件箱中的所有电子邮件。
The below code does not pick up all of my emails in the Inbox.
我的列表框中的第一个项目是昨天的电子邮件,最后一个4 / 22/2014 - 虽然我的邮箱包含比这更多的一个。
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
推荐答案
Next outEmail上的类型不匹配
"type mismatch on the Next outEmail"
收件箱中的项目不需要mailitems。
Items in the Inbox need not be mailitems.
一旦你有Dim outEmail As Variant,在添加到列表框之前,测试outEmail是一个mailitem。
Once you have Dim outEmail As Variant, test that outEmail is a mailitem before adding to the listbox.
这篇关于VBA Outlook Mailitem - 不显示所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文