Skip to content

Instantly share code, notes, and snippets.

@MikeSel
Last active August 29, 2015 14:01
Show Gist options
  • Save MikeSel/296977d74ded9d9b4c90 to your computer and use it in GitHub Desktop.
Save MikeSel/296977d74ded9d9b4c90 to your computer and use it in GitHub Desktop.
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