Public Function olNav2Folder(foldername As String, Optional CheckOnly As Boolean) As object
Dim olApp As Object
Dim olNS As Object
Dim olfldr As Object
Dim reqdFolder As Object
Dim arrFolders() As String
Dim nestCount As Integer
On Error Resume Next
foldername = Replace(Replace(foldername, "/", "\"), "\\", "")
If Right(foldername, 1) = "\" Then foldername = Left(foldername, Len(foldername) - 1)
arrFolders() = Split(foldername, "\")
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set reqdFolder = olNS.folders.Item(arrFolders(0))
For nestCount = 1 To UBound(arrFolders)
If Not reqdFolder Is Nothing Then
Set olfldr = reqdFolder.folders
Set reqdFolder = olfldr.Item(arrFolders(nestCount))
If reqdFolder <> olfldr.Item(arrFolders(nestCount)) Then
If CheckOnly Then
Set reqdFolder = Nothing
Exit For
Else
reqdFolder.folders.Add (arrFolders(nestCount))
Set olfldr = reqdFolder.folders
Set reqdFolder = olfldr.Item(arrFolders(nestCount))
End If
End If
Else
End If
Next
Set olNav2Folder = reqdFolder
Set olApp = Nothing
Set olNS = Nothing
Set olfldr = Nothing
Set reqdFolder = Nothing
End Function
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Commented: