G
Greg
I am working on a program to get the attachments from items in my
inbox. I know that there are 501 items in my inbox.
However, after looking at the 316th item, I get a type mismatch at the
"Next MyMail" line.
Can anyone shed any light on this? Here is my code to recreate the
error.
Is there any other type of item other than a MailItem that is in the
501 count that could be causing the problem?
Private Sub GetAttachments()
Dim OL As Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim InBox As Outlook.MAPIFolder
Dim MyMail As MailItem
Dim MyAttachment As Attachment
Dim numAttachments As Integer
Dim numItems As Integer
Set OL = New Outlook.Application
Set OLNS = OL.GetNamespace("MAPI")
Set InBox = OLNS.GetDefaultFolder(olFolderInbox)
numItems = 0
numAttachments = 1
MsgBox InBox.Items.Count & " items in inbox"
For Each MyMail In InBox.Items
numItems = numItems + 1
txtData.Text = txtData.Text & vbCrLf & numItems
txtData.SelStart = Len(txtData.Text)
Next MyMail
Set OL = Nothing
Set OLNS = Nothing
Set InBox = Nothing
Set MyMail = Nothing
Set MyAttachment = Nothing
' Unload Me
End Sub
Thanks.
Greg
inbox. I know that there are 501 items in my inbox.
However, after looking at the 316th item, I get a type mismatch at the
"Next MyMail" line.
Can anyone shed any light on this? Here is my code to recreate the
error.
Is there any other type of item other than a MailItem that is in the
501 count that could be causing the problem?
Private Sub GetAttachments()
Dim OL As Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim InBox As Outlook.MAPIFolder
Dim MyMail As MailItem
Dim MyAttachment As Attachment
Dim numAttachments As Integer
Dim numItems As Integer
Set OL = New Outlook.Application
Set OLNS = OL.GetNamespace("MAPI")
Set InBox = OLNS.GetDefaultFolder(olFolderInbox)
numItems = 0
numAttachments = 1
MsgBox InBox.Items.Count & " items in inbox"
For Each MyMail In InBox.Items
numItems = numItems + 1
txtData.Text = txtData.Text & vbCrLf & numItems
txtData.SelStart = Len(txtData.Text)
Next MyMail
Set OL = Nothing
Set OLNS = Nothing
Set InBox = Nothing
Set MyMail = Nothing
Set MyAttachment = Nothing
' Unload Me
End Sub
Thanks.
Greg