Referring to the Stack Overflow page above
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
Set Items = GetNS(olApp).GetDefaultFolder(olFolderInbox).Folders("Stuff").Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
MsgBox "You moved an item into the 'Stuff' folder."
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
So if I want to modify the code to refer to another folder, do I write the folder items variable as
Set ThisFolderItems = GetNS(olApp).GetDefaultFolder(olFolderInbox).Folders("ThisFolder").Items
and change the event name to
Private Sub ThisFolderItems_ItemAdd(ByVal item As Object)
Would this work?
I have several folders I would like to keep track of when any item is moved to one of these folders, e.g. Folder1Items, Folder2Items, Folder3Items etc. how do I do this?