Solved

Getting error in collecting an attachment from outlook mail

Posted on 2013-12-01
5
416 Views
Last Modified: 2013-12-02
Hi,
I am geting VBA runtime error -2147221233(8004010f)
The attempted operation failed.An object could not be found.

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim ns As Outlook.Namespace
Dim Inbox As MAPIFolder
Set olApp = CreateObject("Outlook.Application")
Set ns = olApp.GetNamespace("MAPI")

I am geting the above runtime error in below VBA line:

Set Inbox = ns.Session.Folders("Mailbox - test").Folders("Inbox")


Your prompt response would be highly appreciated.
Thanks
references.jpg
0
Comment
Question by:alam747
  • 3
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39688933
Do you actually have a mailbox named  "Mailbox - test" ?

Your overall syntax is fine... but I think you might need to correct your mailbox name (I would think that the mailbox name should be the email address concerned.

Try this as a test instead, to verify that your code works ...
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim ns As Outlook.Namespace
Dim Inbox As MAPIFolder
Set olApp = CreateObject("Outlook.Application")
Set ns = olApp.GetNamespace("MAPI")


Set Inbox = ns.Session.Folders(1).Folders("Inbox")
MsgBox "Folder: " & ns.Session.Folders(1).Name & "     Inbox: " & Inbox.Name

Open in new window

0
 

Author Comment

by:alam747
ID: 39689109
Yes, I have generic mailbox named test.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39689327
Did you try the code I posted?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39689515
Here's something else to try.  This will list all of your mailboxes by name in the debug window.  Pick the one that you need, and copy/paste that mailbox name from the debugger window into your original code where you have "Mailbox - test".  Again, your code seems syntactically correct and works for me - so my guess is that you have a typo or are otherwise not using the correct mailbox name.


Sub ListMailboxes()
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim ns As Outlook.Namespace
Dim Inbox As MAPIFolder
Dim I as integer
Set olApp = CreateObject("Outlook.Application")
Set ns = olApp.GetNamespace("MAPI")

For I = 1 to ns.Session.Folders.Count
         debug.print ns.Session.Folders(I).Name
Next
End Sub

Open in new window

0
 

Author Closing Comment

by:alam747
ID: 39689666
Hi mibizup,

I tested the example code check the result and modified as below then it works.
I removed the mailbox and it works, I updated as below:
Set Inbox = ns.Session.Folders("test").Folders("Inbox")

Thanks for your help
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question