In my case, it worked:
Sub ListMailsInFolder() Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Set objNS = GetNamespace("MAPI") Set objFolder = objNS.Folders.GetFirst ' folders of your current account Set objFolder = objFolder.Folders("Foldername").Folders("Subfoldername") For Each Item In objFolder.Items If TypeName(Item) = "MailItem" Then ' ... do stuff here ... Debug.Print Item.ConversationTopic End If Next End Sub
Similarly, you can also iterate over calendar objects:
Private Sub ListCalendarItems() Set olApp = CreateObject("Outlook.Application") Set olNS = olApp.GetNamespace("MAPI") Set olRecItems = olNS.GetDefaultFolder(olFolderTasks) strFilter = "[DueDate] > '1/15/2009'" Set olFilterRecItems = olRecItems.Items.Restrict(strFilter) For Each Item In olFilterRecItems If TypeName(Item) = "TaskItem" Then Debug.Print Item.ConversationTopic End If Next End Sub
Note that this example uses filtering as well as .GetDefaultFolder(olFolderTasks) to get the built-in folder for calendar items. If you want to access your inbox, for example, use olFolderInbox .
source share