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
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 0
D Wrong email address in Outlook 2003 "From" tab in new outgoing emails Using Outlook 4
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
G Place jpg in body of email Outlook VBA and Custom Forms 1
F Wishlist Outlook suddenly began synchronizing deleted items every time I delete a single email. Using Outlook 2
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 12
F Email being marked as Spam by Gmail and not being visible in Outlook Using Outlook 5
G Email time stamp Using Outlook 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
K Multiple Rules on Single Email Using Outlook 2
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
D Outlook launch email showing new unread email in reading pane Using Outlook 11
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
K Outlook adds space to rows in HTML email signatures viewed on mobile Using Outlook 1
M HTML email signature in Outlook Using Outlook 3
M Respond to Outlook Email Outlook VBA and Custom Forms 0
U Outlook locking up when replying to Email Using Outlook 7
S Email Generated from another program and then edited sends original email. Using Outlook 2
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
S Unable to extract text from an Outlook email message Using Outlook 2
T Original email text not shown when replying or forwarding the email. Using Outlook 9
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
R Problem moving file “Email folders.pst” to new PC Using Outlook 5
P Sending email from outlook IMAP to GMAIL where embedded images are added as attachment Using Outlook 1
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
P How did hacker cause link to delete and archive containing email? Using Outlook 6
I 'quote marks' around email name Using Outlook 1
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0

Similar threads

Top