Solved

Getting error in collecting an attachment from outlook mail

Posted on 2013-12-01
5
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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