#  Other Applications & Softwares  > Outlook Formatting & Functions >  > [SOLVED] Intermittent error on reading sub-folder in Outlook

## dflak

With the help of my friends here on this forum, I was able to write an application to read emails from a folder, download the attachments to a windows folder, and move the email into a subfolder. It works well most of the time. However, if it runs into an error, it not only stops, but fails to work from that point on. I was running the program and encountered the error message in the first picture. I stopped the program and ran it again and got the second error message. I closed Excel, re-opened it and ran the program and got the second error message again. The only way to clear the error is to close Excel, close outlook, open outlook and open excel again.

When it fails, the program always errors on this line:



```
Please Login or Register  to view this content.
```

----------


## dflak

To make the issue even muddier, I reset the system and moved the messages that were being processed when the application failed back into the queue to be reprocessed. All processed perfectly without error. Whatever caused the error the first time did not cause it the second time when as far as I can tell nothing else changed.

----------


## dflak

My best guess is that something was going afoul with the inter-process communication between excel and outlook. The code was probably trying to open the next email before completing the download of the attachment. So, I sprinkled a bunch of DoEvents throughout the code liberally. Last Friday I downloaded 21 messages without error and this morning, I processed a queue of 51 messages without a glitch. So I am marking this one solved.

Here is the final code. My thanks again to the people who stepped in to help me with this program. This is a very repetitive task subject to human errror and well worth automating



```
Please Login or Register  to view this content.
```

----------

