Nested email attachments

Status
Not open for further replies.

Dan_W

Member
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
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
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
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
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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Question about nested distribution lists Outlook VBA and Custom Forms 3
E Duplicate, nested account folders on ATT server Using Outlook 10
M Nested distribution lists: how to count UNIQUE # of people... Outlook VBA and Custom Forms 13
A From a Nested Contact Folder Structure to a Categorised Contact Structure Using Outlook 2
B Deleting Nested Attachments Using Outlook 2
2 Nested or Hierarchical tasks in Outlook 2010? Using Outlook 1
Rupert Dragwater How to permanently remove an email address Using Outlook 9
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 3
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Shift Delete doesn't delete email from server Using Outlook 4
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
L Why are some email automatically going to "archive" Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 8
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 1
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
Albert McCann Outlook 2021 Outlook Display of HTML Email from two senders is glitchy Using Outlook 0
A How Do I Setup My Optonline.Net Email Account? Outlook VBA and Custom Forms 1
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
Wotme create email only data file Using Outlook 1
F Outlook 2016 Email with attachments not being received Using Outlook 3
J Outlook 2019 Regex email addresses from body Outlook VBA and Custom Forms 6
D Prompt to prefix subject line whenever sending an email Outlook VBA and Custom Forms 3
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
C Wishlist Extract or scan new email addresses from out of office replies. Leads from OOO replies Using Outlook 1
T External email warning banner Outlook VBA and Custom Forms 0
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3

Similar threads

Top