objInboxItems_ItemAdd

S

Slava

Hi,

I want to set up a simply test project: at Inbox, when new email will
arrive,
then simply message will be displayed :

ThisOutlookSession :
Private Sub Application_Quit()
Set objInboxItems = Nothing
End Sub

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub


Inserting : Class Modules : objInboxItems :


Private WithEvents objInboxItems As Items

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
MsgBox "New Item Subject: " & Item.Subject
End Sub


save/compile project,
closing Outlook, starting Outlook,
then will appeare dialog about Macro-s, I accept macros,
new email will arrive, but no MsgBox :blush:((

what is wrong in this simply example ?


thank you for any idea,
slava
 
S

Sue Mosher [MVP]

If you put in an Option Explicit statement in your modules, you'd quickly see the problem: You're trying to instantiate objInboxItems in ThisOutlookSession, when objInboxItems is a private variable in a class module.

The easiest fix is to put all the code in ThisOutlookSession.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top