1

Excel から添付ファイルを保存するために、特定のパラメーターに一致するメール アイテムのすべての Outlook フォルダーを調べようとしています。

スコープを参照して、すべてのフォルダー、さらにはカスタム フォルダーを通過する方法がわかりません。

質問に答えるリソースが見つかりません。

Sub testing()

Dim myOlApp As New Outlook.Application
Dim scope As String
Dim filter As String
Dim rsts As Results
Dim AdvancedSearch As Outlook.Search

blnSearchComp = False

'I want it to search the entire mail account including normal folders like inbox and sent as well as custom folders.
'but this doesn't work. Any ideas?
scope = "'Fakeexample123@outlook.com'"
'filter assignment statement has been excluded

Set AdvancedSearch = myOlApp.AdvancedSearch(scope, filter, True, "test")  

While blnSearchComp <> True
    If AdvancedSearch.Results.Count > 0 Then
        blnSearchComp = True
    End If
Wend

Set rsts = AdvancedSearch.Results

For x = rsts.Count To 1 Step -1
    rsts.Attachment.Item(x).SaveAsFile Project
Next

End Sub
4

2 に答える 2

0

まあ、それが最善の解決策ではないことはわかっていますが、すべての親フォルダーのリストを作成する次のコードを思いついたので、高度な検索方法で for ループを使用してリストを反復処理できます。これは最速のコードではありませんが、遅すぎてはいけません。

Sub main()
'establishes connections
Dim myOlApp As New Outlook.Application
Dim objNS As Outlook.Namespace
Dim myFolder As Outlook.MAPIFolder
Set objNS = myOlApp.GetNamespace("MAPI")
'pick highest folder level as original my folder
Set myFolder = objNS.Folders("faxe.example123@outlook.com")

Call ProcessFolders(myFolder)

End Sub

Sub ProcessFolders(myFolder)

're establish connections
Dim myOlApp As New Outlook.Application
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Set objNS = myOlApp.GetNamespace("MAPI")
'set up collection
Set x = New Collection

For Each objFolder In myFolder.Folders
'add all parent folder names to collection
'advanced search method will handle subfolders
'can use a recursive call here also to get subfolders though
    x.Add objFolder.Name
Next


Set objNS = Nothing
Set myFolder = Nothing
Set myOlApp = Nothing

End Sub
于 2015-07-27T18:31:14.577 に答える