ItemAdd event not functioning - not triggering.

Status
Not open for further replies.
B

BlueWolverine

Hello,

MS OUTLOOK 2003 on XP PRO.

What I'm trying to do:

I want to take every email I send, move it to a PST folder, and mark as read

using VBA since this isn't possible in a rule (specifically mark as read).

My Problem:

Through this forum and some other places, I think I have code that's at

least close to doing this. The problem is, the darn thing never triggers.

Please help me with this code. Thank you.

All of what follows is the entirety of a class module.

Dim myolApp As New Outlook.Application

Public WithEvents myOlItems As Outlook.Items

Public Sub Initialize_handler()

Set myOlItems =

myolApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items

End Sub

Public Sub myOlItems_ItemAdd(ByVal Item As Object)

Dim myInbox As Outlook.MAPIFolder

Dim myFolder As Outlook.MAPIFolder

Dim myNewFolder As Outlook.MAPIFolder

Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)

Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)

Set myNewFolder = myInbox.Folders("EMAIL")

Item.Move myNewFolder

Item.UnRead = False

Item.Save

Debug.Print Item.Subject

End Sub

BlueWolverine

MSE - Mech. Eng.

Go BLUE!
 
K

Ken Slovak - [MVP - Outlook]

First things first. If this is running in the Outlook VBA project use the

intrinsic, trusted Application object. Don't use New.

If the code is in a class then are you instantiating an instance of the

class and calling the init code? Usually you'd put the code in the

ThisOutlookSession class, which is automatically instantiated. Then you'd

call your init handler code from the Application_Startup() event handler,

which is automatically available in ThisOutlookSession.

"BlueWolverine" <BlueWolverine> wrote in message

news:99E4EA6A-5FE7-4CEE-A99F-4BEE407F9D22@microsoft.com...
> Hello,

> MS OUTLOOK 2003 on XP PRO.

> What I'm trying to do:
> I want to take every email I send, move it to a PST folder, and mark as
> read
> using VBA since this isn't possible in a rule (specifically mark as read).

> My Problem:
> Through this forum and some other places, I think I have code that's at
> least close to doing this. The problem is, the darn thing never triggers.
> Please help me with this code. Thank you.

> All of what follows is the entirety of a class module.

> Dim myolApp As New Outlook.Application
> Public WithEvents myOlItems As Outlook.Items

> Public Sub Initialize_handler()
> Set myOlItems =
> myolApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
> End Sub

> Public Sub myOlItems_ItemAdd(ByVal Item As Object)

> Dim myInbox As Outlook.MAPIFolder
> Dim myFolder As Outlook.MAPIFolder
> Dim myNewFolder As Outlook.MAPIFolder

> Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)
> Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> Set myNewFolder = myInbox.Folders("EMAIL")

> Item.Move myNewFolder
> Item.UnRead = False
> Item.Save
> Debug.Print Item.Subject

> End Sub

> > BlueWolverine
> MSE - Mech. Eng.
> Go BLUE!
 
D

Diplodok

Hi!

I can not understand, why you want to Mark Item as READ if it is

already marked as READ by default after you sent it?

You can use intrinsic routine ItemSend in class ThisOutlookSession for

catch sent items "on-fly" and set Item.SaveSentMessageFolder to folder

you needed.

However, if You definitely want to set Item.Unread Property to false,

you have to use ItemAdd event for that.

Example:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As

Boolean)

Set Item.SaveSentMessageFolder =

Application.GetNamespace("MAPI").Folders(Outlook

Folders).Folders("Inbox").Folders("MyFolder")

' Also You can set Flag to some Color, If You need point it

Item.FlagIcon = olGreenFlagIcon

End Sub

Again! You can write code string

Item.Uread=False/True

within this proc, but it will overwrite by Outlook on sending to False

-Regards, Andrey
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
oliv- Treat once an email with the ItemAdd event in a shared mailbox Outlook VBA and Custom Forms 2
R outlook 2007 itemadd event handler fails to run Outlook VBA and Custom Forms 2
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3
R Use an ItemAdd to Save Attachments on Arrival Outlook VBA and Custom Forms 0
Diane Poremsky How to use an ItemAdd Macro New Slipstick.com Articles 0
A ItemAdd on Imap Folder get endless loop after saving item Using Outlook 5
G Event when creating task from mailitem Outlook VBA and Custom Forms 2
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
J Outlook 2010 Outlook/Win7 Client logging Event ID 36887 Using Outlook 0
K Recurring all day annual event Using Outlook 3
P Restore an individual all-day recurring event Using Outlook 2
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
K Working with Explorer.Close event Outlook VBA and Custom Forms 3
F Outlook 2016 call to Stop Timer Event Outlook VBA and Custom Forms 4
D Event ID issues Exchange Server Administration 2
J ItemChange event Outlook VBA and Custom Forms 11
T Outlook 2016 Calendar multiday event display Using Outlook 4
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
A UID field in iCal files - unique per-event or per-user or both? Using Outlook 2
D help with Item/Inspector close event Outlook VBA and Custom Forms 1
B on flag message event - create task Outlook VBA and Custom Forms 22
Diane Poremsky Change the All Day Event Default Free/Busy to "Busy" New Slipstick.com Articles 3
C Calendar - Centering an event in Outlook? Using Outlook 1
J Outlook calendar...How to add an event or appointment without a border around it? Using Outlook 9
J Create Calendar Alert Event form Mail Subject line? Using Outlook 4
S Item Add Event fires intermittently Outlook VBA and Custom Forms 3
R Why is a meeting organizer me and not the creator of the event? Using Outlook 1
V Calendar event acting odd Using Outlook 7
G Capture "forward event" ? Outlook VBA and Custom Forms 11
P Change the Outlook.com "from" address for calendar event invites Using Outlook 9
20 Ton Squirrel Detect Application_Startup event completion Outlook VBA and Custom Forms 1
L Outlook 2007 All Day Event Using Outlook 27
I Event listener for deleted items Using Outlook 6
M Save Attachments Event? Using Outlook 0
Commodore Calendar Folder property is missing - Event 27 Using Outlook 11
G Quit event code - 2007 Using Outlook 3
J Capturing forward event when multiple items are selected Using Outlook 0
P Trying to get 'Calendar Name' to appear like 'Subject' and 'Location' in event Calendar Printing Assistant 0
G What event happens when you open 2 copies of your inbox? Using Outlook 5
D Adding a participant automatically to a calendar event Using Outlook 1
H Changing Organizer of event (for single to total calendar move; long way ) Exchange Server Administration 4
N Combobox in outlook add ons toolbar not firing event on main window resized Using Outlook 3
D Extracting Location info from All Day Event in mailboxes into webpage Exchange Server Administration 3
H Conflicts with other event in calendar ( outlook 2007 &amp; 2010) Using Outlook 0
B Restoring Deleted Recurring Event AND Notes Using Outlook 8
Q Looking for Outlook 2010 Close Event Id Exchange Server Administration 1
S Outlook Recurring event Using Outlook 1
D Task and Event View in Outlook 2010? Using Outlook 3
G item_send event Outlook VBA and Custom Forms 4
L Event trigers only first two times from FromRegion. Outlook VBA and Custom Forms 4

Similar threads

Top