![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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 |
Ads |
#2
|
|||
|
|||
![]()
Probably because the item raising the error isn't a MailItem. Never assume; always check the Class. Thus:
Dim itm as Object Dim message as MailItem For Each itm In myItems If itm.Class = olMail Then Set message = itm MsgBox message.SenderEmailAddress, vbOKOnly End If Next -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Pete Dawson (Leeds Uni)" Pete Dawson (Leeds wrote in message ... 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 |
#3
|
|||
|
|||
![]()
A folder can have items other than the regular messages, like non-delivery
reports, meeting invitations, etc. Declare message as a generic object, then check the if the message.Class property is 43 before you access any MailItem specific properties. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Pete Dawson (Leeds Uni)" Pete Dawson (Leeds wrote in message ... 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 |
#4
|
|||
|
|||
![]()
Thanks for the advice, Sue and Dmitry. The program now works OK.
"Sue Mosher [MVP-Outlook]" wrote: Probably because the item raising the error isn't a MailItem. Never assume; always check the Class. Thus: Dim itm as Object Dim message as MailItem For Each itm In myItems If itm.Class = olMail Then Set message = itm MsgBox message.SenderEmailAddress, vbOKOnly End If Next -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Pete Dawson (Leeds Uni)" Pete Dawson (Leeds wrote in message ... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
The current document type cannot be sent as mail | Teddy Banks | Outlook Express | 12 | March 31st 06 02:20 AM |
outlook mail reply window shows very small type | AnthonyD-B | Outlook - General Queries | 2 | February 8th 06 10:42 AM |
how do i find type of mail opened? | Sue Mosher [MVP-Outlook] | Outlook - Using Forms | 0 | February 6th 06 08:13 PM |
Moving a Mix of Mail Items and Report Items | Steve Roberts | Outlook and VBA | 1 | January 24th 06 10:36 PM |
Why is "FAX" a valid e-mail type in address book? | Opus | Outlook - Using Contacts | 3 | January 13th 06 08:24 PM |