Link to home
Start Free TrialLog in
Avatar of alam747
alam747

asked on

Getting error in collecting an attachment from outlook mail

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

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

Avatar of alam747
alam747

ASKER

Yes, I have generic mailbox named test.
Did you try the code I posted?
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alam747

ASKER

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