Link to home
Start Free TrialLog in
Avatar of jpegvarn
jpegvarnFlag for United States of America

asked on

Automating extract of Outlook attachenments and saving as new filename

I need to extract .wav file attachments from incoming email messages and save them as specific filenames based on the subject and the TIME the email was either sent or received (whichever is easiest, prefer sent time) in military format.  The format of the subject is as follows:

[0:33] Message for MB 2102 from x 2296 (FIRSTINITIAL LASTNAME)

The only information needed fromo the subject line is FIRSTINITIAL LASTNAME.  The other information is from the email timestamp.

I need the output filename to follow this format:

hhmmss_FIRSTINITIAL_LASTNAME.wav
(using military time format)


Any ideas?

Tim Mueller
Avatar of David Lee
David Lee
Flag of United States of America image

Hi Tim,

Does this need to be automatic or manual?

Cheers!
Avatar of jpegvarn

ASKER

I am pretty open.  Ideally it would be triggered manually so we can keep an eye on it.

Tim
I like the Outlook attachment sniffer, found here:
http://www.rsbr.de/Software/OASniffer/index_eng.htm
kfalandays
If you're going to run the code manually do you want to select the message it'll process or should it look through all the messages in the folder, presumeably the Inbox, and find the ones matching a condition?
I have tried the Attachment Sniffer.  It works great, but won't let me extract information from the subject line or the message delivery time to create the new filename.  It extracts the attachments perfectly though.

LIke the Sniffer, I'd like the code to search a specific mailbox, find attachments of a specific type (.wav) and save those as the file name structure explained above.

Tim
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Blue Devil Fan;

Thanks for your work.  I can't seem to get the macro to run, though I am betting it's my inexperience with VBA rather than the code itself.  I made the one change in the code I found (strRoot...), saved the file and closed VBA.  I then set the macro security as required, and ran the macro with the Outlook folder I need the macro run against highlighted.  

The PC went to hourglass for a minute, but didn't seem to do anything, nor did the attachments appear in the folder I set "strRoot" to.

Is there something I might have miseed?  Also, am curious as to how you are parsing the subject line to grab the text within the parens (FIRSTINIT LASTNAME).  Keep in mind that this information is in the subject as text;  it is NOT the sender or recipient.  It is placed in the subject by the telephone switch that generates the email attachements and send the email.

Tim
BlueDevilFan,

I think I found the problem!  I cahnged the Root save-to folder to my desktop without realilzing it. I forgot the last \ in the line!  I have 300+ .wav files on my desktop!

I'll make the changes and see what happens.  Thanks again!

Tim
BlueDevilFan;

I was right, my error.  Once I put the ending slash in, the macro worked great.  

A little finetuning and one problem.  I changed the time to hhmm as I don't need the ss after all.

For some reason, the times are off by one hour.  The file name is one hour ahead of the timestamp; ie. the create time is 9:30PM, the file name reflects 2230 (10:30 PM).

Any thoughts?

Tim
> For some reason, the times are off by one hour
Did they come from a different time zone?
Nope, they are local to this network.  The mail server and telephone switch are all right in the building.  I'll have to check the times on the server to be sure, but they "should" be correct.
jpegvarn,

This is the line of code where I get the date

    strTime = Format(olkMessage.SentOn, "hhmmss")

As you can see I'm not changing it, just formatting it to remove the colons.  If the sent date shows right in the message and wrong here, then I don't have an explanation.
I will check on the time issues later today/tomorrow.

Just ran into a new wrinkle.  It appears that if the subject line doesn't fiollow the (firstinitial lastname) setup, I get a subscript out of range error.  IS there a trap that can be placed in the code to allow (anything) to work?

Tim
I can certainly alter the code to not give an error, but if the (Firstinitial Lastname) isn't in the subject line and in some consitent format, then I won't be able to contruct the file name.