reubendayal
Senior Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi All,
Under one of my mail boxes, I have several client folders as a sub sub folder. And it is a bit time consuming when working on the laptop screen to scroll up and down to locate the folder and archive the emails to it or even open it and work on the emails from it. I have looked around and found the below code seems to do an okay job. And I have added the source folder from which the code should search under. However, it seems to hang outlook for a few seconds (20-40 seconds) each time I use it which simply ends up being way too slow and not very useful.
Could you help me clean up the code to make it work faster. or suggest another way of searching through the folder names to find the case folder by its name and then open it?
Thanks so much!
Under one of my mail boxes, I have several client folders as a sub sub folder. And it is a bit time consuming when working on the laptop screen to scroll up and down to locate the folder and archive the emails to it or even open it and work on the emails from it. I have looked around and found the below code seems to do an okay job. And I have added the source folder from which the code should search under. However, it seems to hang outlook for a few seconds (20-40 seconds) each time I use it which simply ends up being way too slow and not very useful.
Could you help me clean up the code to make it work faster. or suggest another way of searching through the folder names to find the case folder by its name and then open it?
Thanks so much!
Code:
'****Finding folders by name****
Private m_Folder As Outlook.MAPIFolder
Private m_Find As String
Private m_Wildcard As Boolean
Private Const SpeedUp As Boolean = False 'True
Private Const StopAtFirstMatch As Boolean = True
Public Sub FindFolder()
Dim Name$
Dim Folders As Outlook.Folders
Set m_Folder = Nothing
m_Find = ""
m_Wildcard = False
Name = InputBox("Find name:", "Search folder")
If Len(Trim$(Name)) = 0 Then Exit Sub
m_Find = Name
m_Find = LCase$(m_Find)
m_Find = Replace(m_Find, "%", "*")
m_Wildcard = (InStr(m_Find, "*"))
Set Folders = Application.Session.Folders("DK Maerskimmigration").Folders("Inbox").Parent.Folders("Assignees 2019") 'Application.Session.Folders
LoopFolders Folders
If Not m_Folder Is Nothing Then
If MsgBox("Activate folder: " & vbCrLf & m_Folder.FolderPath, vbQuestion Or vbYesNo) = vbYes Then
Set Application.ActiveExplorer.CurrentFolder = m_Folder
End If
Else
MsgBox "Not found", vbInformation
End If
End Sub
Private Sub LoopFolders(Folders As Outlook.Folders)
Dim F As Outlook.MAPIFolder
Dim Found As Boolean
If SpeedUp = False Then DoEvents
For Each F In Folders
If m_Wildcard Then
Found = (LCase$(F.Name) Like m_Find)
Else
Found = (LCase$(F.Name) = m_Find)
End If
If Found Then
If StopAtFirstMatch = False Then
If MsgBox("Found: " & vbCrLf & F.FolderPath & vbCrLf & vbCrLf & "Continue?", vbQuestion Or vbYesNo) = vbYes Then
Found = False
End If
End If
End If
If Found Then
Set m_Folder = F
Exit For
Else
LoopFolders F.Folders
If Not m_Folder Is Nothing Then Exit For
End If
Next
End Sub