I have a macro in Outlook, i need it to run everytime a new mail comes to my inbox...how do i do that??
Printable View
I have a macro in Outlook, i need it to run everytime a new mail comes to my inbox...how do i do that??
In the VB editor (Press Alt + F11), add this code.
VB Code:
Private Sub Application_NewMail() Call YouMacroName End Sub
Thanks for that, it works. My macro manipuates my emails and stores them on some form outside. Now sometimes i get two mails at the same time, so macro works fr the first email and does nt fr the other as it is nt new nemore. how do i gt the macro 2 wrk fr all unread mails...
ne help wud b gr8
You need to loop through the Inbox folder and check if the items
are new mail or not.
VB Code:
Private Sub Application_NewMail() Dim oNS As Outlook.NameSpace Dim oInbox As Outlook.MAPIFolder Dim oEmail As Outlook.MailItem Dim i As Integer Set oNS = Application.GetNamespace("MAPI") Set oInbox = oNS.GetDefaultFolder(olFolderInbox) i = 0 'Loop through the inbox marking unread emails as read. Do While oInbox.UnReadItemCount > 0 And i < oInbox.Items(i).Count i = i + 1 If oInbox.Items(i).UnRead = True Then Set oEmail = oInbox.Items.Item(i) oEmail.UnRead = False 'Do more stuff here '... '... '... Set oEmail = Nothing End If Set oInbox = Nothing Set oInbox = oNS.GetDefaultFolder(olFolderInbox)'Refresh Loop End Sub
Thanks a lot mate!! it works like a beauty now...much appreciated the help
Your welcome, glad to help.