Hello All
I found a thread from a while back that dealt with this but I need to get some help with the code I found there. here is my scenario:
I would like to run this against the mainstore of my outlook account so that anytime an email from the inbox is moved to any other mail folder it will be tagged with a date. this code looks like it would do the job, but I have more than 2 folders that I want to "watch". in fact I need to watch any folder that holds mail items, especially if a new folder is created.
Another problem is the fact that these emails might not be moved within the current open outlook session on my computer but might be moved by someone else who has been given full access through exchange server. the situation is that we have a "pool" address that receives all of our service email and is delegated to various people. when someone is given the task it moves to a "My_tasks\persons name" folder. when they complete it they move it to a "completed\country" folder.
I was thinking that if I put the "watch" on the mainstore that might work, I haven't tried it yet, I thought I would get this post in so that I could get feedback on the idea asap as I am on a time crunch with the code.
here is the code I had found:
Private WithEvents Items1 As Outlook.Items
Private WithEvents Items2 As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' change these lines to point to the subfolders you are moving emails to
Set Items1 = objNS.GetDefaultFolder(olFolderInbox).Folders("SubFolder 1").Items
Set Items2 = objNS.GetDefaultFolder(olFolderInbox).Folders("SubFolder 2").Items
End Sub
Private Sub Items1_ItemAdd(ByVal item As Object)
On Error Goto ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
' change this to do what you want with the information, i.e. generate a new email, write info to spreadsheet, etc
Debug.Print Msg.ReceivedTime & " " & Msg.SenderName & " " & Msg.Subject & " " & Format(Now, "mm/dd/yyyy") & " " & Items1.Parent.Name
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Private Sub Items2_ItemAdd(ByVal item As Object)
On Error Goto ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
' change this to do what you want with the information, i.e. generate a new email, write info to spreadsheet, etc
Debug.Print Msg.ReceivedTime & " " & Msg.SenderName & " " & Msg.Subject & " " & Format(Now, "mm/dd/yyyy") & " " & Items2.Parent.Name
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
any and all help is appreciated.