The operation failed. An object could not be found.

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...
 
G

Guest

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.
 
G

graftonfot

I'll try this, but a question:

What will:
Set SubFolder = ParentFolder.Folders.Add(SpecificSubject)


....do if the folder already exists?

Thanks very much.
 
G

Guest

It will generate an error ("Unable to create folder"), so make sure you
utilize some error handling.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top