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!
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]"