[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting error in collecting an attachment from outlook mail

Posted on 2013-12-01
5
Medium Priority
?
565 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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 …
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…

830 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