I\'m trying to use Outlook VBA to loop through the inbox and list the from email address if the subject matches a string. Got this so far from googling, but it\'s not workin
As commented, try incorporating a test for MailItem in your code:
Dim objNS As Outlook.NameSpace: Set objNS = GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim Item As Object
For Each Item In olFolder.Items
If TypeOf Item Is Outlook.MailItem Then
Dim oMail As Outlook.MailItem: Set oMail = Item
Debug.Print oMail.SenderEmailAddress
End If
Next
Edit1: As suggested by Dmitry, you can also use:
If Item.Class = 43 Then
in place of
If TypeOf Item Is Outlook.MailItem Then