PDA

View Full Version : How Do I Determine What an Item Is?



Cartaphilus
09-11-2008, 12:26 PM
The following bit of code loops through an Outlook folder and pulls up the items in it:

Set myNewFolder = myFolder.Folders(y)
x = myNewFolder.Items.Count

'loop through each item in the folder
For i = 1 To x
Set mynewitem = myNewFolder.Items.Item(i)
.
.
.

'mynewitem' will be either a message or a meeting invitation or a meeting invitation response. My question is, how do I determine in code which of the three 'mynewitem' is?

TIA...

jfournier
09-11-2008, 12:40 PM
use the typeof function in vba. here's an example of how you might use it:

If TypeOf mynewitem Is Outlook.MailItem Then
'do something
ElseIf TypeOf mynewitem Is Outlook.MeetingItem Then
'do something
ElseIf TypeOf mynewitem Is Outlook.AppointmentItem Then
'do something
End If

Mavyak
09-12-2008, 01:43 PM
The Class property is a good indicator too.
If Item.Class = olMail Then
MsgBox "I'm a MailItem!"
End If