![]() |
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
|
|||
|
|||
![]()
Hi, I would like to get some code that shows me how to use the TypeName
function to determine whether the current item I am about to use is in fact a mailitem and not something else? -- Thanks David G Albury, Australia |
Ads |
#2
|
|||
|
|||
![]()
There's not much to it:
If TypeName(whatever_item_you_want) = "MailItem" Then ' you know it's a mailItem -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "David G" wrote in message news ![]() Hi, I would like to get some code that shows me how to use the TypeName function to determine whether the current item I am about to use is in fact a mailitem and not something else? -- Thanks David G Albury, Australia |
#3
|
|||
|
|||
![]()
Or you can use the Class property
if whatever_item_you_want.Class = 43 Then Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Sue Mosher [MVP-Outlook]" wrote in message ... There's not much to it: If TypeName(whatever_item_you_want) = "MailItem" Then ' you know it's a mailItem -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "David G" wrote in message news ![]() Hi, I would like to get some code that shows me how to use the TypeName function to determine whether the current item I am about to use is in fact a mailitem and not something else? -- Thanks David G Albury, Australia |
#4
|
|||
|
|||
![]()
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 OR 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 Much appreciated. -- Thanks David G Albury, Australia "Dmitry Streblechenko" wrote: Or you can use the Class property if whatever_item_you_want.Class = 43 Then Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Sue Mosher [MVP-Outlook]" wrote in message ... There's not much to it: If TypeName(whatever_item_you_want) = "MailItem" Then ' you know it's a mailItem -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "David G" wrote in message news ![]() Hi, I would like to get some code that shows me how to use the TypeName function to determine whether the current item I am about to use is in fact a mailitem and not something else? -- Thanks David G Albury, Australia |
#5
|
|||
|
|||
![]()
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. -- SvenC |
#6
|
|||
|
|||
![]() I prefer TypeOf: If TypeOf obj Is Outlook.MailItem Then ... ElseIf TypeOf obj Is Outlook.ContactItem Then ... Endif It's much faster than comparing strings. Referring to Sven, here you can fully qualify the object type, and it's not dependent on the existence of the Class property. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Organize eMails: http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6 Am Sat, 21 Jul 2007 08:44:42 -0400 schrieb Sue Mosher [MVP-Outlook]: There's not much to it: If TypeName(whatever_item_you_want) = "MailItem" Then ' you know it's a mailItem -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "David G" wrote in message news ![]() Hi, I would like to get some code that shows me how to use the TypeName function to determine whether the current item I am about to use is in fact a mailitem and not something else? -- Thanks David G Albury, Australia |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search the Web Function | GMS | Outlook Express | 1 | February 2nd 07 07:23 PM |
Sub or Function not defined | ladyhawke | Outlook and VBA | 3 | January 27th 07 08:06 PM |
Find function | jwb | Outlook - Using Contacts | 1 | December 11th 06 05:32 PM |
Reply function | bill | Outlook Express | 4 | November 12th 06 05:11 PM |
GetPublicFolder() function | Morgan | Outlook and VBA | 1 | April 18th 06 01:01 PM |