This adjustment adds message subjects to the appropriate node, just in case you wanted that:
VB Code:
Private Sub cmdGetFolders_Click() 'Required Treeview Control named tvw 'Reference to Microsoft Outlook 9.0 Object Library Dim oApp As Outlook.Application Dim oNameSpace As NameSpace Dim oFolder As MAPIFolder Dim oMailItem As Object Dim cFolder As MAPIFolder Dim sFolder As MAPIFolder Dim myItems As Items Dim MailCounter As Integer, FolderCount As Integer Dim sMessage As String Set oApp = New Outlook.Application Set oNameSpace = oApp.GetNamespace("MAPI") Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox) tvw.Nodes.Add , , "inbox", oFolder mCounter = 0 For Each oMailItem In oFolder.Items mCounter = mCounter + 1 tvw.Nodes.Add "inbox", tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem Next For FolderCount = 1 To oFolder.Folders.Count Set cFolder = oFolder.Folders(FolderCount) tvw.Nodes.Add "inbox", tvwChild, "mail" & FolderCount, cFolder For Each oMailItem In cFolder.Items mCounter = mCounter + 1 tvw.Nodes.Add "mail" & FolderCount, tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem Next If cFolder.Folders.Count <> 0 Then 'check for 1 more layer of sub folders For nFolderCount = 1 To oFolder.Folders.Count Set sFolder = oFolder.Folders(nFolderCount) If sFolder <> cFolder Then tvw.Nodes.Add "mail" & FolderCount, tvwChild, "mail" & FolderCount & nFolderCount, sFolder For Each oMailItem In sFolder.Items mCounter = mCounter + 1 tvw.Nodes.Add "mail" & FolderCount & nFolderCount, tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem Next End If Next End If Next Set oMailItem = Nothing Set oFolder = Nothing Set mFolder = Nothing Set oNameSpace = Nothing Set oApp = Nothing End Sub




Reply With Quote