none
Check for the existence of a property (VB Script)

    שאלה

  • The following script fragment works nicely - well, almost:

        Set oOutlook   = CreateObject("Outlook.Application")
        Set oNamespace = oOutlook.GetNamespace("MAPI")
        Set oInbox    = oNamespace.GetDefaultFolder(InboxFolder)

        For Each oMail In oInbox.items
            If oMail.SenderEMailAddress = . . .

    It successfully checks the sender of each mail but it runs into trouble when a mail item does not have the property "SenderEMailAddress" (e.g. an Outlook Task item). Hence my question: How can I determine if this property exists? I could, of course, trap the resulting error condition but I am looking for a more elegant solution.

    יום שני 27 פברואר 2012 20:00

תשובות

  • Thanks for your help. After some searching I did find a method that does not involve error trapping.

        Set oOutlook   = CreateObject("Outlook.Application")
        Set oNamespace = oOutlook.GetNamespace("MAPI")
        Set oInbox    = oNamespace.GetDefaultFolder(InboxFolder)

        For Each oMail In oInbox.items
            if oMail.Class = 43 then WScript.Echo oMail.SenderEMailAddress
        Next

    I was unable to locate a dictionary of classes but it seems that mail items are class 43 whereas tasks are 49.

    יום שני 27 פברואר 2012 23:15

כל התגובות