PDA

View Full Version : Solved: looping through emails and getting data



next
06-19-2012, 07:51 AM
I haven't dealt with Outlook VBA yet, so this is my first attempt and I'm getting nowhere :dunno
Here's what I'm trying to do: I have a folder "CWI Customers", within that folder there's another one "AEO". I need to go through all emails in that folder, then retrieve the subject line and attachment name.

To test how things work I figured I'll just get the title of all items in my inbox, but it's not working. Here's my code:
Sub test()
Dim ns As NameSpace
Dim item As Object
Dim inbox As MAPIFolder
'Dim sub_folder As MAPIFolder

Set ns = GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
'Set sub_folder = inbox.Folders("AEO")

For Each item In inbox
Debug.Print item.Title
Next item
End Sub

skatonni
06-21-2012, 04:50 AM
Sub test()
Dim ns As NameSpace
Dim item As Object
Dim inbox As MAPIFolder
'Dim sub_folder As MAPIFolder

Set ns = GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
'Set sub_folder = inbox.Folders("TEST")

For Each item In inbox.items
If TypeOf item Is mailItem Then
Debug.Print item.Subject
End If
Next item
End Sub