With this example, it’s possible to use the ‘WithEvents’ methods on a folder outside of your own mailbox.
This even works on Public Folders!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | Dim WithEvents olkFolder As Outlook.MAPIFolder Sub InitMonitoring() Set olkFolder = OpenOutlookFolder("Path to the folder to monitor") End Sub Function IsNothing(obj) If TypeName(obj) = "Nothing" Then IsNothing = True Else IsNothing = False End If End Function Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder Dim arrFolders As Variant, _ varFolder As Variant, _ olkFolder As Outlook.MAPIFolder On Error GoTo ehOpenOutlookFolder If strFolderPath = "" Then Set OpenOutlookFolder = Nothing Else If Left(strFolderPath, 1) = "" Then strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1) End If arrFolders = Split(strFolderPath, "") For Each varFolder In arrFolders If IsNothing(olkFolder) Then Set olkFolder = Session.Folders(varFolder) Else Set olkFolder = olkFolder.Folders(varFolder) End If Next Set OpenOutlookFolder = olkFolder End If On Error GoTo 0 Exit Function ehOpenOutlookFolder: Set OpenOutlookFolder = Nothing On Error GoTo 0 End Function |














