Are macros enabled? File, Options, Trust Center, Macros. Set it to enable all to test.
I have entered some code lifted from the Slipstick site and pasted it into the "ThisOutlookSession" area. Basically, all it is supposed to do is just popup a msgbox when an email arrives.
I have relaunched Outlook to pick up the new code, but nothing happens when an email arrives. I simply cannot believe that it is this hard to just display a message! I have the feeling that Outlook is ignoring the code altogether - we are using the cloud (Office 365) version. Is this why.
Getting so frustrated with this!
Can anyone give me a steer with this
thanks!
Are macros enabled? File, Options, Trust Center, Macros. Set it to enable all to test.
Diane Poremsky [MVP - Outlook]
Outlook & Exchange Solutions Center
Outlook Tips
Outlook Tips by email
EMO - a weekly newsletter about Outlook and Exchange
Hi Diane,
Thanks for your response.
I have now set the Trust Centre on Macros to "Enable all macros (not recommended.....blah)
I have restarted Outlook twice now, but nothing happens when I receive an email.
The VBA code is lifted from your website:
Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.Items
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)
Dim objEmail As Outlook.MailItem
'Ensure we are only working with e-mail items
If Item.Class <> OlItemType.olMailItem Then Exit Sub
MsgBox "Message subject: " & objEmail.Subject & " inro ASK Finance mailbox", vbCritical
'Debug.Print "Message sender: " & objEmail.SenderName & " (" & objEmail.SenderEmailAddress & ")"
Set objEmail = Nothing
End Sub
And is pasted into ThisOutlookSession folder.I'm expecting to get the normal VB msgbox popup in the middle of the screen.
I don't really even know how I can test the VBA ie. Make it do something to definitely confirm is awake and talking.
Any ideas?
many thanks
This line is not working -
If Item.Class <> OlItemType.olMailItem Then Exit Sub
The last sub that does the work is
Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
MsgBox "Message subject: " & Item.Subject & " inro ASK Finance mailbox", vbCritical
End Sub
are you trying to watch a secondary mailbox? You'll need to tell it to watch that folder - Working with VBA and non-default Outlook Folders - Slipstick Systems - but I'm not 100% sure it will work.
Diane Poremsky [MVP - Outlook]
Outlook & Exchange Solutions Center
Outlook Tips
Outlook Tips by email
EMO - a weekly newsletter about Outlook and Exchange
This works with secondary accounts when the mailbox is open in the profile - the mailbox name as it appears in the folder list goes into the line marked bold (right click on the inbox in the folder, choose properties and copy the mailbox name ). And you need the GetFolderPath function from the link I posted earlier.
Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.Items
Private Sub Application_Startup()
Dim objMyInbox As Outlook.MAPIFolder
Set objNewMailItems = GetFolderPath("Forum Replies\Inbox").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 <> OlItemType.olMailItem Then Exit Sub
MsgBox "Message subject: " & Item.Subject & " into ASK Finance mailbox", vbCritical
End Sub
Diane Poremsky [MVP - Outlook]
Outlook & Exchange Solutions Center
Outlook Tips
Outlook Tips by email
EMO - a weekly newsletter about Outlook and Exchange
Thanks once again Diane.
However, setting up code in the VBA window is not much good if Office 365 is suppressing execution.
How can I test this?
Can i for instance pop-up a msgbox when I launch Outlook? That would certainly
indicate whether or not VBA is being processed properly. t6rouble is, i do not know the event
or what things I have to set up to acheive this.
Thanks
Office365 hosted Exchange? That is what I tested it with - my mailbox and a managed mailbox in my profile (it's added automatically when I create the profile - an automated version of Account Settings, double click on my account, More Settings then add a secondary mailbox).
If you are opening it using Open other users folder, I'm not sure a macro will work on it.
Application_startup is the one that runs on start up.
Code:Private Sub Application_Startup() msgbox "Welcome" Dim objMyInbox As Outlook.MAPIFolder Set objNewMailItems = GetFolderPath("Forum Replies\Inbox").Items Set objMyInbox = Nothing End Sub
Diane Poremsky [MVP - Outlook]
Outlook & Exchange Solutions Center
Outlook Tips
Outlook Tips by email
EMO - a weekly newsletter about Outlook and Exchange
Bookmarks