フォルダーの場所として文字列を入力するにはどうすればよいですか。\ MySpecificEmailAddress \ Inbox Outlookを使用してVBAでそのフォルダを選択するには?次を使用してパスを取得しました。
... = ActiveExplorer.CurrentFolder.FolderPath
フォルダーを選択してスクリプトを実行しなくても、マクロを実行する特定のフォルダーをスクリプトに自動的に指示するために、広範囲にわたって検索しました。
特定のメールボックスのすべてのフォルダを列挙Session.Stores
してからアクセスできる必要があります。Store.GetRootFolder.Folders
いくつのレベルに進む必要があるかによって、これにはもう少し手間がかかる場合があります(つまり、再帰)。
これは、メールボックス/ストアのルートフォルダーの下にあるすべてのフォルダーを列挙するMSDNのコードスニペットです。
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)
Dim folders As Outlook.folders
Dim Folder As Outlook.Folder
Dim foldercount As Integer
On Error Resume Next
Set folders = oFolder.folders
foldercount = folders.Count
'Check if there are any folders below oFolder
If foldercount Then
For Each Folder In folders
Debug.Print (Folder.FolderPath)
EnumerateFolders Folder
Next
End If
End Sub