trouble with e-mail save macro

  • Thread starter Thread starter NakedJ
  • Start date Start date
N

NakedJ

I use Outlook 2002 and have written a macro to save e-mails on a
location on the hard drive. It works (mostly), but when I try to run
it on a larger group of files, it doesn't save all of the files.

We take care of same-name e-mails as a business process, so that does
not explain the emails that won't save. (I am trying to automate the
same-name e-mail problem as well, but that's a seperate issue.)

Here is the code:

On Error Resume Next

Randomize
iMsgCnt = 0

For Each sMsg In cf.Items
If sMsg.GetInspector.EditorType = olEditorWord Then
sMsg.SaveAs MyOrt & StripChars(sMsg.Subject) & ".RTF",
olRTF
ElseIf sMsg.GetInspector.EditorType = olEditorText Then
sMsg.SaveAs MyOrt & StripChars(sMsg.Subject) & ".txt",
olTXT
ElseIf sMsg.GetInspector.EditorType = olEditorRTF Then
sMsg.SaveAs MyOrt & StripChars(sMsg.Subject) & ".RTF",
olRTF

Else: sMsg.SaveAs MyOrt & StripChars(sMsg.Subject) &
".HTML", olHTML


End If

What am I missing?
 
As the loop isn't complete, do you move the message after it's saved? If so,
loop backwards through the list.
I didn't post the whole thing. What I left out was:

iMsgCnt = iMsgCnt + 1
Next

I believe that this "closes the loop".

The messages do not get moved/removed automatically. Should I still
loop backwards? How do I do that?.

Thanks for the response, I will research more on looping backwards.
 
I didn't post the whole thing. What I left out was:

iMsgCnt = iMsgCnt + 1
Next

I believe that this "closes the loop".

The messages do not get moved/removed automatically. Should I still
loop backwards? How do I do that?.

Thanks for the response, I will research more on looping backwards.

Did some testing this morning, it appears that file size has something
to do with it. For example, if I strip attachments, I get 236 out of
246 emails saved, compared to 29 of 246. (Using the same emails
otherwise. Still not getting all of them though.

Any other ideas? The files that are being missed are not linear, that
is, they are not necessarily the last ten that are missing.

Jason
 
What happens if you delete the On Error Resume Next line?

This is a backwards loop:

For i=Items.count To 1 step -1
....
next

But it's only necessary if you move or delete items from the collection.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Fri, 27 Jul 2007 15:21:06 -0000 schrieb NakedJ:
On Jul 27, 1:28 am, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:> As the loop isn't complete, do you move the message after it's saved? If so,
loop backwards through the list.

I didn't post the whole thing. What I left out was:

iMsgCnt = iMsgCnt + 1
Next

I believe that this "closes the loop".

The messages do not get moved/removed automatically. Should I still
loop backwards? How do I do that?.

Thanks for the response, I will research more on looping backwards.

Did some testing this morning, it appears that file size has something
to do with it. For example, if I strip attachments, I get 236 out of
246 emails saved, compared to 29 of 246. (Using the same emails
otherwise. Still not getting all of them though.

Any other ideas? The files that are being missed are not linear, that
is, they are not necessarily the last ten that are missing.

Jason
 
What happens if you delete the On Error Resume Next line?
Nothing. I have found out the problem. There were inherent problems
in the code that caused my HTML files not to save the body of the
email, as well as an incomplete "stripchars" code. I was running into
problems with emails that had a "/" or "\" in them. this problem was
easily solved.

I changed the code to look for bodyformat property instead of editor
property, and to include the created date/time to prevent same subject
e-mail problem.

Now I can save all e-mails to files.

Last feature I would like to add is a count function that will show
"Saved X out of Y e-mails." Any ideas to get me started? This is not
a deal breaker.

Thanks for your help.

Jason
 
After one message is saved increase iMsgCnt by 1. The total is
cf.Items.Count. you can display a message with the MsgBox function.
Thanks for all of the help. Instead, I added an error log function
so that I can identify problem files. I may still add the count
function though, it seems like ti would be pretty straight forward.

Cheers
 
Back
Top