我想选择一个特定的邮箱(收件箱,存档邮箱等)并按名称查找特定文件夹。
我想有一个选项,它不会只显示一个结果但是如果在特定的收件箱中会有两个相同的子文件夹,会显示第一个,如果我接受它而不是关闭,如果不是我可以转到下一个结果。
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)
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
总结: 如果脚本会在特定的收件箱或功能邮箱中找到特定的文件夹(我将指出),并显示符合条件的每个结果,那就足够了。
答案 0 :(得分:0)
要选择文件夹,请使用“Pickfolder”。 http://msdn.microsoft.com/en-us/library/office/ff869969%28v=office.15%29.aspx
在离开LoopFolders之前确认找到了正确的文件夹,而不是之后。
在LoopFolders中移动测试并测试F.
If MsgBox("Do you want to go to this folder ?" & vbCrLf & _
F.FolderPath, vbQuestion Or vbYesNo, _
"TheTechieguy.com - Found your Folder:") = vbNo Then
Found = False
End If
If Found Then