View Single Post
  #2  
Old May 18th 10, 08:55 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default ItemAdd event not functioning - not triggering.

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"BlueWolverine" wrote in message
...
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(olFo lderSentMail).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!


Ads