VBA Quandary: The Attempted Operation Failed. Oject could not be found (Second Time running only)

hellfire45

Active Member
Joined
Jun 7, 2014
Messages
462
Hi Guys. So I have this VBA script and I am getting the error Run-Time Error '-2147221233 (8004010f): The Attempted operation failed. An object could not be found.

This error only happens the second time I run the script. If I close outlook and Excel, reopen and run, it's fine. If I then run again without restarting the applications, I get the error. The error is occurring on the line below (Set fldr_inv = olFolder.Folders("Complete"))
I'm basically just trying to set a variable to a sub-folder inside of this inbox. Supplier Enablement >> Inbox >> Complete

Very perplexing that it works the first run but not the second. I tried googling but this didn't help. Any ideas? Thanks guys!

VBA Code:
Dim olApp As New Outlook.Application
Dim olNameSpace As Object
Dim olFolder As Object
Dim fldr_inv As Outlook.MAPIFolder

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.Folders("Supplier Enablement").Folders("Inbox")
Set fldr_inv = olFolder.Folders("Complete")

Set myItems = olFolder.Items
myItems.Sort "[ReceivedTime]"
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top