跳到主要內容

如何在Outlook中按文件夾名稱查找文件夾(完整的文件夾路徑)?

例如,在“導航”窗格中,您移動了一個文件夾,然後在Outlook中將其錯誤地放到了一個未知的文件夾中,您想還原此文件夾,但無法立即找到它。 不幸的是,Outlook不支持 發現 與Microsoft Word或Excel中的功能相同。 別擔心! 您可以應用VBA宏來解決Outlook中的此問題。

使用出色的工具按文件夾名稱快速搜索和打開文件夾

通常,我們可以使用VBA代碼按文件夾名稱搜索文件夾。 大多數VBA代碼可以搜索當前郵箱中的文件夾,並僅打開找到的第一個文件夾。 現在有了Kutools for Outlook的“轉到”功能,您可以輕鬆地按文件夾名稱輕鬆查找文件夾,並根據需要打開找到的任何文件夾。



使用VBA按文件夾名稱查找文件夾(完整文件夾路徑)

請按照以下步驟在Outlook中使用VBA按文件夾名稱搜索文件夾。

1。 按 其他 + F11 鍵一起打開Microsoft Visual Basic for Applications窗口。

2。 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到新的“模塊”窗口中。

VBA:在Outlook中按文件夾名稱搜索和打開文件夾

Private m_Folder As MAPIFolder
Private m_Find As String
Private m_Wildcard As Boolean

Private Const SpeedUp As Boolean = True
Private Const StopAtFirstMatch As Boolean = True

Public Sub FindFolder()
Dim sName As String
Dim oFolders As Folders

  Set m_Folder = Nothing
m_Find = ""
m_Wildcard = False

  sName = InputBox("Find:", "Search folder")
If Len(Trim(sName)) = 0 Then Exit Sub
m_Find = sName

  m_Find = LCase(m_Find)
m_Find = Replace(m_Find, "%", "*")
m_Wildcard = (InStr(m_Find, "*"))

  Set oFolders = Application.Session.Folders
LoopFolders oFolders

  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 oFolder As MAPIFolder
Dim bFound As Boolean

If SpeedUp = False Then DoEvents

  For Each oFolder In Folders
If m_Wildcard Then
bFound = (LCase(oFolder.Name) Like m_Find)
Else
bFound = (LCase(oFolder.Name) = m_Find)
End If

    If bFound Then
If StopAtFirstMatch = False Then
If MsgBox("Found: " & vbCrLf & oFolder.FolderPath & vbCrLf & vbCrLf & "Continue?", vbQuestion Or vbYesNo) = vbYes Then
bFound = False
End If
End If
End If
If bFound Then
Set m_Folder = oFolder
Exit For
Else
LoopFolders oFolder.Folders
If Not m_Folder Is Nothing Then Exit For
End If
Next
End Sub

3。 按 F5 鍵或單擊 按鈕以運行此VBA。

4。 在彈出的搜索文件夾對話框中,輸入您要搜索的指定文件夾名稱,然後單擊 OK 按鈕。 看截圖:

備註:此VBA支持星號通配符。 例如,您可以輸入 特斯* 找出所有名稱以開頭的文件夾 工商業污水附加費.

5。 現在出現一個對話框,顯示找到的文件夾的文件夾路徑。 如果您需要打開找到的文件夾,請單擊 按鈕。

現在,找到的文件夾正在“導航”窗格中打開,如下圖所示:

備註:如果有多個使用指定名稱命名的文件夾,則此VBA只能找到並打開一個文件夾。


通過出色的工具按文件夾名稱搜索文件夾

如果您安裝了Kutools for Outlook,則可以使用其轉到功能快速按特定的文件夾名稱查找所有文件夾,並輕鬆打開找到的任何文件夾。

Kutools for Outlook:透過 100 多種必備工具增強 Outlook 功能。 60 天免費試駕,無任何附加條件!   閱讀更多...   現在就下載!

1。 點擊 Kutools 加 > 轉到 啟用此功能。

2。 在“轉到”對話框中,請在 檢索 框,在搜索結果中選擇一個文件夾,然後單擊 Ok 按鈕。

現在,找到具有特定文件夾名稱的指定文件夾並立即打開。


相關文章:


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you for this great macro. I have used it extensively over the past 2 years. My employer switched from Office 16 to Office 365 and since then, this macro is VERY slow. Is there any way to optimize it for Office 365?
Thanks!
This comment was minimized by the moderator on the site
This macro has really helped me is incredible, thank you!!!
Is it possible to to go to the next occurrence, so instead of just Yes/No have something as Yes/Next/No ?
Thank you
This comment was minimized by the moderator on the site
Private m_Folder As MAPIFolder
Private m_Find As String
Private m_Wildcard As Boolean

Private Const SpeedUp As Boolean = True
'Private Const StopAtFirstMatch As Boolean = True
Private StopAtFirstMatch As Boolean

Public Sub FindFolder()
Dim sName As String
Dim oFolders As Folders

Set m_Folder = Nothing
m_Find = ""
m_Wildcard = False

sName = InputBox("Find:", "Search folder")
If Len(Trim(sName)) = 0 Then Exit Sub

'm_Find = sName
' Added "*"... for any given string in the folder name
m_Find = "*" & sName & "*"

m_Find = LCase(m_Find)
m_Find = Replace(m_Find, "%", "*")
m_Wildcard = (InStr(m_Find, "*"))

' Set oFolders = Application.Session.Folders
Set oFolders = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders

LoopFolders oFolders

If Not m_Folder Is Nothing Then
' Removed - If MsgBox("Activate folder: " & vbCrLf & m_Folder.FolderPath, vbQuestion Or vbYesNo) = vbYes Then
Set Application.ActiveExplorer.CurrentFolder = m_Folder
Else
MsgBox "Search End...", vbInformation
End If
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders)
Dim oFolder As MAPIFolder
Dim bFound As Boolean

If SpeedUp = False Then DoEvents

For Each oFolder In Folders
If m_Wildcard Then
bFound = (LCase(oFolder.Name) Like m_Find)
Else
bFound = (LCase(oFolder.Name) = m_Find)
End If


If bFound Then
If StopAtFirstMatch = False Then
Set Application.ActiveExplorer.CurrentFolder = oFolder

If MsgBox("Found: " & vbCrLf & oFolder.FolderPath & vbCrLf & vbCrLf & "Search for next?", vbQuestion Or vbYesNo) = vbYes Then
bFound = False
End If
Else
MsgBox ("Not found")
End If
End If
If bFound Then
Set m_Folder = oFolder
Exit For
Else
LoopFolders oFolder.Folders
If Not m_Folder Is Nothing Then Exit For
End If
Next
End Sub
This comment was minimized by the moderator on the site
Hi, if i try to copy and past the macro yes/next/no, I only received the message "Search End".
Could you take a look? I would really appreciate it. Thanks
This comment was minimized by the moderator on the site
Hi, if i try to copy and past the macro yes/next/no, I only received the message "Search End".Could you take a look? I would really appreciate it. Thanks
This comment was minimized by the moderator on the site
Wow this is exactly. I really appreciate it and you did it so fast.Thanks
This comment was minimized by the moderator on the site
Hello,

Thank you for this macro. It works great!


Is there a way to make the macro always search as wildcards? I would be easier to just type a keyword without adding the asterisks every time.
This comment was minimized by the moderator on the site
Replace Line 18 with

m_Find = "*" & sName & "*"
This comment was minimized by the moderator on the site
Replace Line 18 with
m_Find = "*" & sName & "*"
This comment was minimized by the moderator on the site
Hello.

Wow - this is an amazing function, which will make my daily usage of Outlook tons faster.
Thank you so much for publishing!!

A tip for those interested:
If you want to search only INBOX-folders, without public folders etc.
This made it a lot faster for me because the public folder are remote, so the search is quite slow.
And also I'm not interested in those results.


Replace line 24 with:

Set oFolders = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations