PDA

View Full Version : Save messages and Attachments Hierarchially



steveolson1
12-08-2008, 03:09 PM
Hello All!

First Posting here. I've seen bits and pieces of what I want but not quite.

I am very experienced in using VBA in Access, but almost no experience in Outlook. (The agency I work for changed to Outlook a couple of months ago.)

WHat I would like to find is a piece of Outlook VBA that will cycle through all of the folders in my mailbox, and for any message that has attachments, do the following:

For each attachment in a message, it would save a copy of the message (RTF if possible, Text if not) and a copy of the attachments to a folder hierarchy containing the Outlook Folder name, then the name of the Sender, then the date and time of the message containing the attachment.

For example if I have a message from John Doe in my Inbox, with an attachment name of Sales.PDF and a message Date/Time of Dec 10, 2008 09:25:03, I would end up with it saved:

BaseFolder\Inbox\John Doe\2008-12-10_09-25-03\Sales.PDF
and
BaseFolder\Inbox\John Doe\2008-12-10_09-25-03\Sales.RTF (or Sales.TXT)

If I have more than one email from John Doe (even the same day with the same attachments but at different times) this shoud eliminate the possibility of over-writing attachments of the same names.

I would also like to then remove the attachments from the email, but put a line at the bottom that he attachment was deleted that includes the full path where the attachment now resides.

I know this complex of a script is a tall order, but I think it would give me and maybe a lot of others some good code samples to do a lot of things I currently don't have a clue about.


Thanks,

Steve Olson

steveolson1
12-12-2008, 02:00 PM
Since I've gotten no response on this in 4 days, I thought I'd boil it down to what I thought the tasks were that were necessary to do this (I’ve simplified my request a bit):

1. Cycle through all of the messages in all of the folders in my mailbox (But being able to call this on demand from a toolbar button would be good too, also the possibility of having this run when new mail would come in as well)

2. For each message (put files saved below into folders named with the same names as the folders the messages were from):
a. Save an RTF version of the message, with it titled by the Date/Time (to the second) of the message and the Sender Name (with illegal characters stripped and only the username without the domain.) – If message was received from John Doe (jdoe@hotmail.com (jdoe@hotmail.com)) at 6:10:31 on July 12th, 2008, then the filename would be: “20080712_061031_jdoe.RTF”
b. If a message has attachments, do a. above, but also save a copy of each attachment named as in a. but with the attachment name on the end. If the message mentioned in a. above had 2 attachments, Orders.XLS and Memo.DOC then they would be named “20080712_061031_jdoe_Orders.XLS” and “20080712_061031_jdoe_Memo.DOC”
c. Add a line at the message top of the message indicating the attachment was removed and the name of the attachment as it was saved in 2b. IE “ **Attachment Removed** - 20080712_061031_jdoe_Orders.XLS” or something similar. 1 line per attachment
d. Remove the attachments from the message.

Also, if anyone has a few links to good Outlook coding sites besides this one, I’d appreciate it. If you can put me onto some code samples to do any part of this it would be greatly appreciated.

I’ve already found code to do #1 above, but only for a specific folder like Sent Messages or the Inbox, not all of them. I’ve also yet to find a good source as to how to programmatically access all of the parts of the message like time/date of message, subject, from, etc. If anyone knows of a good source of this please post a link.

I know general VBA quite well, having worked several years with it in developing Access applications, but I’m a very green newbie when it comes to programming Outlook.

If I manage to cobble this together myself before seeing responses here I'll post what I come up with.


Thanks,

Steve Olson

GTO
12-13-2008, 12:24 AM
Greetings Steve,

While I'm certainly not "all that" when it comes to Outlook, this is interesting to me. Would you mind posting the code you have thus far? I have an idea or two, but want to take what you have already with the (little bit of) code I wrote thus far, and run it by a buddy (Demosthine).

I bet we can help:yes .

Also - welcome to the forum! Be patient, as particularly Outlook code doesn't seem to draw a plethora of coding, but there are some great and awfully helpful folks here.

I'll check back Monday, Tuesday at the latest (if not before, but this weekend looks rather "smoked").

Hope to help,

Mark

steveolson1
12-13-2008, 02:59 PM
I didn't have anything concrete yet, just some concepts. However, I have gathered a few snippets of code from here and other sources, and will try to throw it all together this weekend. If not, I probably won't get to it until Tuesday, as Monday at 530AM I have a family member going in for heart surgery.

I guess a good start to this would be code that could save the attachment then add a line to the message stating that was done, then delete the attachemnt.

So far I've gotten code that will cycle through all of the messages in a particular folder (like Sent messages or the Inbox), but don't yet have anything that will recurse through all folders in my mailbox.

Thanks....

Steve Olson

JP2112
12-16-2008, 08:45 PM
This might get you started. The code found on this page will iterate through every folder in your Outlook hierarchy.

http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun06/hey0616.mspx

HTH



Hello All!

First Posting here. I've seen bits and pieces of what I want but not quite.

I am very experienced in using VBA in Access, but almost no experience in Outlook. (The agency I work for changed to Outlook a couple of months ago.)

WHat I would like to find is a piece of Outlook VBA that will cycle through all of the folders in my mailbox, and for any message that has attachments, do the following:

For each attachment in a message, it would save a copy of the message (RTF if possible, Text if not) and a copy of the attachments to a folder hierarchy containing the Outlook Folder name, then the name of the Sender, then the date and time of the message containing the attachment.

For example if I have a message from John Doe in my Inbox, with an attachment name of Sales.PDF and a message Date/Time of Dec 10, 2008 09:25:03, I would end up with it saved:

BaseFolder\Inbox\John Doe\2008-12-10_09-25-03\Sales.PDF
and
BaseFolder\Inbox\John Doe\2008-12-10_09-25-03\Sales.RTF (or Sales.TXT)

If I have more than one email from John Doe (even the same day with the same attachments but at different times) this shoud eliminate the possibility of over-writing attachments of the same names.

I would also like to then remove the attachments from the email, but put a line at the bottom that he attachment was deleted that includes the full path where the attachment now resides.

I know this complex of a script is a tall order, but I think it would give me and maybe a lot of others some good code samples to do a lot of things I currently don't have a clue about.


Thanks,

Steve Olson