ItemAdd event not functioning - not triggering.

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
 
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.
 
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
 

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