Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fire a macro when a message is moved to a specific subfolder

115 views
Skip to first unread message

Barney Mowder

unread,
Jul 16, 2004, 5:04:36 PM7/16/04
to
All-

I am looking for a way to fire a VBA macro when a message is moved
from Inbox to a specific subfolder of inbox. Is there an event
associated with this action?

The scenario is this. I'm a systems admin, and I receive a huge
number of NDRs every day, and I need a way to sort them sanely. The
rules wizard doesn't allow me to fire a macro based on any of the
standard tests, but I CAN move the message to a subfolder based on
these tests.

What I want to have happen is that when an NDR gets moved to a
subfolder called NDRs, a macro associated with the NDRs folder gets
run on the new member.

Is this possible? If not, what workarounds exist?

Thank you for your time and trouble,

Barney

Eric Legault [MVP - Outlook]

unread,
Jul 20, 2004, 4:23:06 PM7/20/04
to
Assuming NDRs is a sub-folder of your Inbox, the code below should do what you want. Just alter the Item_Add event to run the macro you desire.

Paste this code into your ThisOutlookSession module:

Option Explicit
Dim WithEvents objNDRFolderItems As Outlook.Items

Private Sub Application_Startup()
On Error Resume Next

Dim objInbox As Outlook.MAPIFolder, objNS As Outlook.namespace
Dim objFolder As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Folders("NDRs")
Set objNDRFolderItems = objFolder.Items
End Sub

Private Sub Application_Quit()
Set objNDRFolderItems = Nothing
End Sub

Private Sub objNDRFolderItems_ItemAdd(ByVal Item As Object)
'note that ItemAdd may not fire if large number of items are added to it at the same time
'run a macro
'RunMyProcedure
End Sub

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

Barney Mowder

unread,
Jul 21, 2004, 12:21:51 PM7/21/04
to
Eric-

It works like a charm! THANK YOU!!! Definitely, you ARE an MVP.
Your prediction RE large numbers of messages is dead on, too.

Barney

"Eric Legault [MVP - Outlook]" <elega...@REMOVEZZZmvps.org> wrote in message news:<15E211FD-8763-4ABA...@microsoft.com>...

belot...@gmail.com

unread,
Dec 3, 2014, 3:12:30 PM12/3/14
to
FRAUD TERRORIST FIAT ALLIS, EMC.COM APPLE, GOV FRAUD MONEY LAUNDERING IS TERRORIST. STOLEN VALOR ACT CRIMES, FEDERAL IRS CRIMES, ATTEMPTED MURDER, STALKING CHILDTEN. PORN, SELLING PORN, YOU ARE A PIECE A WORK. SO MANY FOLLOERS, WHY.....NOTHING BUT A CRIMINAL, PIECE OF SHIT.
0 new messages