Skip to content

Instantly share code, notes, and snippets.

@DBremen
Created December 23, 2019 13:55
Show Gist options
  • Save DBremen/b463592182dd9b0b9e84b776c3316c30 to your computer and use it in GitHub Desktop.
Save DBremen/b463592182dd9b0b9e84b776c3316c30 to your computer and use it in GitHub Desktop.
Find outlook folder
'Note: this code was written with bit and pieces taken from the web
'Use it - have fun - good luck :)
'TheTechieGuy.com
'ver 1.0
Private MyFolder As Outlook.MAPIFolder
Private MyFolderWild As Boolean
Private MyFind As String
Public Sub FindFolder()
Dim Name$
Dim Folders As Outlook.Folders
Set MyFolder = Nothing
MyFind = ""
MyFolderWild = False
Name = InputBox("Enter the Folder Name that you would like to find:" + vbCrLf + vbCrLf + "Note: you can use Wildcards such as * or ?", "TheTechieguy.com - Search My Folders:")
If Len(Trim$(Name)) = 0 Then Exit Sub
MyFind = Name
MyFind = LCase$(MyFind)
MyFind = Replace(MyFind, "%", "*")
MyFolderWild = (InStr(MyFind, "*"))
Set Folders = Application.Session.Folders
LoopFolders Folders
If Not MyFolder Is Nothing Then
If MsgBox("Do you want to go to this folder ?" & vbCrLf & MyFolder.FolderPath, vbQuestion Or vbYesNo, "TheTechieguy.com - Found your Folder:") = vbYes Then
Set Application.ActiveExplorer.CurrentFolder = MyFolder
End If
Else
MsgBox "The folder you were looking for can not be found.", vbCritical, "TheTechieguy.com - Folder NOT found:"
End If
End Sub
Private Sub LoopFolders(Folders As Outlook.Folders)
Dim F As Outlook.MAPIFolder
Dim Found As Boolean
For Each F In Folders
If MyFolderWild Then
Found = (LCase$(F.Name) Like MyFind)
Else
Found = (LCase$(F.Name) = MyFind)
End If
If Found Then
Set MyFolder = F
Exit For
Else
LoopFolders F.Folders
If Not MyFolder Is Nothing Then Exit For
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment