Last active
August 29, 2015 14:01
-
-
Save MikeSel/296977d74ded9d9b4c90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment