Nested email attachments

Dan_W

Member
Best answers
0
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
Hello,

I've been visiting these forums for some time now, and I've always managed to solve whatever challenges I've had with my code, but I'm slightly stumped with the logic (at least) of what it is I'm trying to do with a macro in Outlook. I would be grateful for any guidance or suggestions, because as much as I google it, I can't quite find the right answer.

I expect the code would be straightforward, but I just can't wrap my head around the logic of it. In essence:

1. User selects a number of email - these emails will each have attachments to them.
2. The emails and the attachments are downloaded to the local drive.
3. HOWEVER, it is likely that these attachments are a mix of both MSG ("Attachment Email") and standard attachments (e.g., DOCX, PDF, etc).
4, The macro then needs to save the attachments to the Attachment Emails, until all the attachments are saved.
5. THEN, all of the Attachment Emails need to be sorted chronologically, and arranged/printed in order. If there is an attachment to an Attachment Email, that will need to sit appended to the corresponding parent email.

Saving the attachments to the hard drive is ok (.SaveAsFile), thank you Slipstick (Saving Attachments to the Hard Drive). I'm stuck on the sorting part. Do I reimport the MSG files back into Outlook? CreateItemFromTemplate and then sort and then re-export?

I feel like I'm over thinking this.

Again, any guidance would be greatly appreciated. Thank you.

Dan
 

Diane Poremsky

Senior Member
Best answers
0
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I dont think importing/exporting will help - its not going to fix windows sorting. Windows sorts by created, saved or mod date - the emails will use the date you saved them. I would get the date from the message and either add it to the filename or update the filesystem properties so you can sort by a property field.
 

Dan_W

Member
Best answers
0
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
Hi Diane

I only just managed to come back to this forum this evening owing to work demands, so I apologise for not replying earlier.

Thank you for taking the effort to set out your thoughts - as it so happens I stumbled across the perfect solution by accident an hour or so after having posted the question on this forum. The short story is:-

1. I was overthinking it; and
2. You were absolutely right - the key was to add a date/timestamp at the front of filenames (yyyymmdd-hhmmss).

The subroutine works its way through each email in the selection, saves it to the designated folder with a filename composed of the date/time of the email and the subject of email (stripped of illegal characters): (yyyymmdd-hhmmss_SubjectOfEmail.msg).

If that email had any attachments, then those attachments are saved to the designated folder with a filename composed of the date/time of the parent email and then its actual filename unless the relevant attachment was itself an MSG file, in which case it would set about going through the process again recursively, but this time with its own date/time as the working date/timestamp. The final result was several hundred documents in a folder, all perfectly arranged chronologically.

It turns out that the total count was 56 emails (parent emails + nested emails), and the total non-MSG attachments was 228 documents. Needless to say, this saved us a lot of time.

I will look into cleaning up the code and posting it for others to use (or critique). Thank you again.
 

andrew fawcett

New Member
Best answers
0
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Hi - sorry to ask a stupid question about attachments, but having trouble starting a new question, so thought it better to write on the above subject.

When i make a task, i always initially insert a copy of the email that i have received into that task using a quickstep to 'Make a Task with attachment' When i get extra emails about the same task, i 'insert outlook item' into that task. This way i can track the complete task without having to go anywhere else. Easy.

My problem is that additionally to the 'insert outlook item' that is being done, i also want to forward the message that im 'inserting' into an email to a separate person. I know that this can be done via an outlook quickstep, but i want both of the actions to be done at the same time, and the quickstep cannot do both. Not being terribly up to speed with VBA, do you have any templates that i might borrow and tweak to allow both the actions to be done please. Any help gratefully appreciated.
 

Diane Poremsky

Senior Member
Best answers
0
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can use this as a base then add code to forward.

Using first macro, add forward code after the end with:

Code:
With objTask
    .Subject = objMail.Subject
    .DueDate = objMail.ReceivedTime + 3
    .StartDate = objMail.ReceivedTime + 2
     objSel.PasteAndFormat (wdFormatOriginalFormatting)
    .Categories = "From Email"
   ' .Save
    .Save
    .Display
    .Attachments.Add objMail
End With

    objMail.Categories = "Task" & objMail.Categories
Forward code would be:

Code:
Set objForward = objMail.Forward
oForward.display
If you always forward to the same address, you can add the address and send it too.
 
Top