The operation failed. An object could not be found.

  • Thread starter Thread starter graftonfot
  • Start date Start date
G

graftonfot

I'm trying to get an Outlook macro running which will store emails from
a mailing list subscription into subfolders arranged by subject.

There is a tag string included in each subject line which I'm using to
identify these emails. I then do a little bit of parsing on the
subject line to get the specific subject. Then I check to see if a
subfolder by that name exists, if not I create it, then move the email
there.

This worked once. After the creation of the first subject subfolder,
it began to fail. It is failing at the point at which I attempt to
determine whether or not a subdirectory already exists for the current
subject:

1 Set SubFolder = Nothing
2 Set SubFolder = ParentFolder.Folders(SpecificSubject)
3 ' If it doesn't, create it
4 If SubFolder Is Nothing Then
5 ParentFolder.Folders.Add (SpecificSubject)
6 Set SubFolder = ParentFolder.Folders(SpecificSubject)
7 End If

Here, ParentFolder is an existing subfolder under which I want to
create the subfolders. When line 2 executes, I get "The operation
failed. An object could not be found." If I set a breakpoint at line
2 and add a watch for ParentFolder, it seems fine (has a Folders member
which seems to contain 1 subfolder.)

Any ideas as to why I am getting this error?

Thanks in advance...
 
What happens if you try this instead:

Set SubFolder = ParentFolder.Folders.Add(SpecificSubject)
If Not SubFolder Is Nothing Then
'Good folder
End If

Also, I'd retrieve the Folders collection into its own variable instead of
calling it directly through ParentFolder.
 
It will generate an error ("Unable to create folder"), so make sure you
utilize some error handling.
 
Back
Top