我想选择一个特定的邮箱(收件箱、存档邮箱等)并按名称查找特定的文件夹。
我希望有一个选项,它不会只向我显示一个结果,但如果在特定收件箱中有两个相同的子文件夹,将向我显示第一个,如果我接受它,则关闭案例,如果没有,我可以转到下一个结果。
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
概括:如果脚本在特定收件箱或功能邮箱中找到特定文件夹,我将指出该文件夹并显示与标准匹配的每个结果,那就足够了。
要选择文件夹,请使用 Pickfolder。 http://msdn.microsoft.com/en-us/library/office/ff869969%28v=office.15%29.aspx
确认在离开 LoopFolder 之前(而不是之后)找到了正确的文件夹。
将测试移动到循环文件夹内并测试 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