A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

TypeName Function



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 21st 07, 07:00 AM posted to microsoft.public.outlook.program_vba
David G
external usenet poster
 
Posts: 4
Default TypeName Function

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  
Old July 21st 07, 01:44 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default TypeName Function

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  
Old July 21st 07, 09:47 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default TypeName Function

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  
Old July 22nd 07, 06:46 AM posted to microsoft.public.outlook.program_vba
David G
external usenet poster
 
Posts: 4
Default TypeName Function

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  
Old July 22nd 07, 02:39 PM posted to microsoft.public.outlook.program_vba
SvenC
external usenet poster
 
Posts: 11
Default TypeName Function

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  
Old July 23rd 07, 06:24 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default TypeName Function



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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 04:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.