I have some code that imports emails into a form. However, it gets caught up on calender invites an such. As a response, I would like to filter out all these calender invites so they are not even trying to import in the first place. This is the code i have so far:
Dim SenderCheck As String
'Build the list selection box
j = 0
For i = 1 To Emails.Count
With ListBox_Emails
If TypeName(Item) = "MailItem" Then
SenderCheck = Emails(i).Sender.Address
If InStr(1, SenderCheck, "express-scripts.com") > 0 Then
.AddItem Emails(i).Sender
.List(j, 1) = Emails(i).Subject
.List(j, 2) = Emails(i).ReceivedTime
.List(j, 3) = "N"
j = j + 1
Else: MsgBox "error"
End If
Else: MsgBox "not mail item"
End If
End With
On Error GoTo TEMP
The issue is with the line If TypeName(Item)="MailItem" then
as everything is now deemed not a mail item and I get the "Not a mail item" error.
How would I go about fixing this issue? I think the syntax is incorrect but I can not figure out how to correct it.