P
Pete Dawson (Leeds Uni)
Trying to scan through mail messages in Outlook 2003 SP2. The code below
works OK if the messages are in the Inbox but not if they are in a mail
subfolder. I created this code from an earlier macro that worked fine in
Outlook XP. As you can tell from the variable names, most of it came from
Outlook VBA help. I tried declaring 'message' as an Outlook.MailItem but got
error 13 - Type mismatch.
Any ideas?
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
' Dim message as Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
' Works if next line is commented out
Set myFolder = myFolder.Folders("Mail shot replies")
Set myItems = myFolder.Items
For Each message In myItems
' Next line gives run-time error 438
' "Object doesn't support this property or method"
MsgBox message.SenderEmailAddress, vbOKOnly
Next message
works OK if the messages are in the Inbox but not if they are in a mail
subfolder. I created this code from an earlier macro that worked fine in
Outlook XP. As you can tell from the variable names, most of it came from
Outlook VBA help. I tried declaring 'message' as an Outlook.MailItem but got
error 13 - Type mismatch.
Any ideas?
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
' Dim message as Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
' Works if next line is commented out
Set myFolder = myFolder.Folders("Mail shot replies")
Set myItems = myFolder.Items
For Each message In myItems
' Next line gives run-time error 438
' "Object doesn't support this property or method"
MsgBox message.SenderEmailAddress, vbOKOnly
Next message