Alex Cotton
New Member
- Outlook version
- Outlook 2016 32 bit
- Email Account
- Office 365 Exchange
Hello, I am reasonably experienced in using VBA for Excel, but new in Outlook.
I copied some basic inbox new mail trigger code that should work. However, I get an "invalid or unqualified reference" refering to "item".
Can someone please give me a pointer as to where to look. I have googled for a long time, but cannot get this working.
Using Office 365 / Outlook 2016 (16.0.9126.2282) 32 bit.
The code I have:
Private Sub Application_Startup()
Dim objMyInbox As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objNewMailItems = objMyInbox.Items
Set objMyInbox = Nothing
End Sub
Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
'Ensure we are only working with e-mail items
If Item.Class <> olMail Then Exit Sub
Debug.Print "Message subject: " & Item; .Subject
Debug.Print "Message sender: " & Item; .SenderName & " (" & Item; .SenderEmailAddress & ")";
End Sub
I have put the relevant "item" in bold and blue.
Thanks in advance, and apologies for what has to be a really naïve obvious question.
I copied some basic inbox new mail trigger code that should work. However, I get an "invalid or unqualified reference" refering to "item".
Can someone please give me a pointer as to where to look. I have googled for a long time, but cannot get this working.
Using Office 365 / Outlook 2016 (16.0.9126.2282) 32 bit.
The code I have:
Private Sub Application_Startup()
Dim objMyInbox As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objNewMailItems = objMyInbox.Items
Set objMyInbox = Nothing
End Sub
Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
'Ensure we are only working with e-mail items
If Item.Class <> olMail Then Exit Sub
Debug.Print "Message subject: " & Item; .Subject
Debug.Print "Message sender: " & Item; .SenderName & " (" & Item; .SenderEmailAddress & ")";
End Sub
I have put the relevant "item" in bold and blue.
Thanks in advance, and apologies for what has to be a really naïve obvious question.