Solved

Getting error in collecting an attachment from outlook mail

Posted on 2013-12-01
5
382 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now