×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Outlook; user environment differences

Outlook; user environment differences

Outlook; user environment differences

(OP)
The script below opens the Outlook default Inbox of the logged-in user. It displays the number of emails in the inbox, then interates through the first 4 emails, displaying sender and subject.

I log in as UserOne. The script is in a shared folder. When I run the script, it works exactly as expected.

Then, I log on as UserTwo. The script fails at assigning the sender and subject variables:
Object doesn't support this property method: 'objEmailItem.SenderEmailAddress'

Same machine, same code, same Outlook install. Different users. Clearly something different in the user environment, or registry, or something similar. It's beyond me what it might be. Does objEmailItem and objOutlook come from objNameSpace? Is that's what is different between the two? Outlook was already on the machine when I logged on as each (domain) user for the first time, creating these two fresh local profiles. What could be different?

Users are the same in terms of security. Both are common domain users but in the local admin group on this machine.

I need to find out how these two users can both run this script consistently without crashing.

------------------------------
Const olFolderInbox = 6
CR = chr(13)

Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox)

MsgBox("Total Items: " & objFolder.Items.Count & CR & "Total Unread items: " & objFolder.UnReadItemCount)

count = 0

For Each objEmailItem In objFolder.Items

EmailAddrStr = objEmailItem.SenderEmailAddress
EmailSenderStr = objEmailItem.Sender
EmailSubjectStr = objEmailItem.Subject

count = count + 1

MsgBox(Count & " " & EmailAddrStr & CR & EmailSenderStr & CR & EmailSubjectStr & CR)

If count = 4 Then
Exit For
End If
Next

objOutlook.Quit

Set objEmailItem = Nothing
Set objFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

RE: Outlook; user environment differences

(OP)
Microsoft doc says:
Use GetNameSpace ("MAPI") to return the Outlook NameSpace object from the Application object.
In the script above, that's Set objOutlook =
Not sure how would that vary by user.

RE: Outlook; user environment differences

The problem is almost certainly that objEmailItem is not actually an email item, but rather one of the various Items that Outlook uses. One way of handling that might be to put a check into your loop, eg:

CODE

    For Each objEmailItem In objFolder.Items
        If objEmailItem.Class = 43 Then 'Const olMail = 43
            EmailAddrStr = objEmailItem.SenderEmailAddress
            EmailSenderStr = objEmailItem.Sender
            EmailSubjectStr = objEmailItem.Subject

            Count = Count + 1

            MsgBox (Count & " " & EmailAddrStr & CR & EmailSenderStr & CR & EmailSubjectStr & CR)

            If Count = 4 Then
                Exit For
            End If
        Else
            ' If you want to do anything with non-email items ...
        End If
    Next 

RE: Outlook; user environment differences

(OP)
Thanks, that's an eye opener for me. As it turns out, you've pointed out something I had not considered - for the user that's not having the trouble - that inbox was formerly an Exchange public folder and yes, also has PDFs and Word docs in it. For working user, only email. I will look at this on Monday.

RE: Outlook; user environment differences

>only email

there are items that superficially appear to be Mailitems, but are not, eg non-delivery reports, which are typically classified as ReportItems. You can see what is tripping the affected user up with another very simple modification that I left room for in my example code:

CODE

    For Each objEmailItem In objFolder.Items
        If objEmailItem.Class = 43 Then ' Const olMail = 43
            EmailAddrStr = objEmailItem.SenderEmailAddress
            EmailSenderStr = objEmailItem.Sender
            EmailSubjectStr = objEmailItem.Subject

            Count = Count + 1

            MsgBox (Count & " " & EmailAddrStr & CR & EmailSenderStr & CR & EmailSubjectStr & CR)

            If Count = 4 Then
                Exit For
            End If
        Else
            ' If you want to do anything with non-email items …
            MsgBox "Non-mailitem - " & objEmailItem.Class & ": " & TypeName(objEmailItem)
        End If
    Next  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close