Hi David,
Thank you Sue and Dmitry for your posts, I presume therefore that I can
declare a generic object variable called objItem as Object and place that
into the function for a true or false answer as in:
If TypeName(objItem) = "MailItem" Then
'it is confirmed that it is a mail item
Else
'I can display an error message to the user
End if
The problem might be with common class names which exist in difference
namespaces, like Folder which exists in Outlook, Scripting, CDO and so on.
To be sure just assign an object to a variable of the type you want and do
proper runtime error handling, e.g.
Dim oMI as Outlook.MailItem
On Error Resume Next
Set oMI = objItem
If Not oMI Is Nothing Then
' it is a MailItem
Else
' it is not a MailItem
End If
If TypeName(objItem.Class) = 43 Then
'it is confirmed that it is a mail item
Else
'I can display an error message to the user
End if
No, this goes without TypeName, just objItem.Class = 43. But this will fail
on Objects which do not expose a Class property. So you would net runtime
error handling as well.
TypeName(objItem.Class) might also fail, when property Class does not exist.
If it does exist if will return the type of the property Class. For Outlook
objects it should be Long, the data type used for the olObjectClass enum.