Save attachments with date-time received


  1. Posts : 955
    Windows 10 x64
       #1

    Save attachments with date-time received


    Outlook 365

    Am seeking a way to save attachments,

    with sender name and date-time stamp 'received' added to the file names.

    Any suggestions?
      My Computer


  2. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #2

    Diane P's suggestions are useful:
    Save and Rename Outlook Email Attachments - Slipstick Systems
    Rename Outlook Attachments - Slipstick Systems
    and there are relevant threads in StackOverflow & elsewhere
    How do you rename an attachment and save it in outlook? - SO
    How to rename attachments in Outlook window without saving to disc - EO

    The nearest equivalent I have is that I use this VBA code to add date-time to an open email Subject property so you could investigate applying a similar approach to attachments.
    Code:
    Sub SetUniqueTitle()
    Dim a
    Dim DTG
    Dim myOlApp As New Outlook.Application
    Dim myItem As Object
    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.ActiveInspector.CurrentItem
    If Application.ActiveExplorer.CurrentFolder.Name = "Sent Items" Then WhoBy = "tx" Else WhoBy = "rx"
    ' SentOn format is 09/03/2023 19:27:42
    DTG = Mid(myItem.SentOn, 7, 4) & Mid(myItem.SentOn, 4, 2) & Left(myItem.SentOn, 2) & " " & Mid(myItem.SentOn, 12, 2) & Mid(myItem.SentOn, 15, 2) & Mid(myItem.SentOn, 18, 2)
    ' Correct for case of 00:00:00 {exactly midnight}.  This happened once in 2021 after having used these scripts for over twenty years.
    If Len(Mid(myItem.SentOn, 12, 2) & Mid(myItem.SentOn, 15, 2) & Mid(myItem.SentOn, 18, 2)) = 0 Then DTG = Mid(myItem.SentOn, 7, 4) & Mid(myItem.SentOn, 4, 2) & Left(myItem.SentOn, 2) & " 000000"
    myItem.Subject = DTG & " " & WhoBy & " " & myItem.Subject
    myItem.Save
    End Sub

    Running my code for a sample email changes its subject from
    Reply to thread 'Microsoft e-mail'
    to
    20230309 192742 rx Reply to thread 'Microsoft e-mail'

    I put a link to my code in Outlook's open email Quick access toolbar.



    Best of luck,
    Denis
    Last edited by Try3; 10 Mar 2023 at 06:18.
      My Computer


  3. Posts : 955
    Windows 10 x64
    Thread Starter
       #3

    Thanks a lot! I will check it out.

    I already did check out some sites, also Stackoverflow.
    Most sites rely on VBA.
    No problem, except I am not familiar with VBA.
    I know how to add a script and run it, but I am not familiar with VBA itself.
    Reason why I hesitate to apply them, not knowing exactly what it is going to do.

    I will check out Slipstick.
    Save Attachments to the Hard Drive

    Thanks again.
      My Computer


  4. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #4

    If you are happy to save the attachments to the hard drive & add the date etc there then that can be done manually.
    - Open File explorer, put it on the left side of your display, browse to your chosen folder.
    - Put Outlook on the right side of your display, open the email.
    - In Attached: grab the attachment's icon and drag it into your chosen folder.

    The attachment is now just a file and you can rename it however you want.
    But you will have lost the chance of using VBA to rename the attachment to match the date-time the email was received. That data was only available within Outlook.


    All the best,
    Denis
      My Computer


  5. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #5

    tfwul said:
    I know how to add a script and run it, but I am not familiar with VBA itself.
    I'm not particularly familiar with VBA either. Anything I do in it takes me ages to write & test.
    If I am writing something new or just trying out lines of code I've found online I often find it useful to display each new command line in a MsgBox instead of actioning it so I can see exactly what it's doing with the variables in use and then follow that line with a Stop line so it does not go any further.
    So, for example, my line
    Code:
    DTG = Mid(myItem.SentOn, 7, 4) & Mid(myItem.SentOn, 4, 2) & Left(myItem.SentOn, 2) & " " & Mid(myItem.SentOn, 12, 2) & Mid(myItem.SentOn, 15, 2) & Mid(myItem.SentOn, 18, 2)
    started life as two lines
    Code:
    MsgBox Mid(myItem.SentOn, 7, 4) & Mid(myItem.SentOn, 4, 2) & Left(myItem.SentOn, 2) & " " & Mid(myItem.SentOn, 12, 2) & Mid(myItem.SentOn, 15, 2) & Mid(myItem.SentOn, 18, 2)
    Stop 'Check this before letting the code run any further
    and I'd gradually work my way down the draft script testing each bit as I went. The 'proper' ways of doing this are built-in to the VBA Editor and include use of the Immediates pane.


    That script I posted above was my very first VBA script and it took me at least a week to write.
    I've been using it since the late nineties to set my email Subject fields before dragging emails into File explorer folders for long-term storage where the email Subject becomes its filename.
    - Hence the title of that VBA above. Each file in a File explorer folder needs a unique filename so I have to do something with sets of emails all called RE This weekly report - discussions
    - I discovered a bug in the code in 2021 after having used the script for over twenty years. A proper programmer might have coped with that midnight condition straightaway but I had not even thought about it until it happened. I have added the midnight correction to the earlier post just in case you end up playing with it. [I must have copied & pasted it from an earlier backup before. It is now exactly what I use in Outlook.]


    One complicating factor in VBA is that varies between Office applications albeit only to a small extent. So you have to search on, say, Outlook VBA SaveAs to avoid picking up irrelevant results concerning Excel VBA.
    - This is eased for me because I have not updated from Office 2007 & my VBA Help is built-in to each application rather than being obtained through online searches so I don't get messed up by stray results.
    - There are lots of online guides but I tend to use them as references to help me overcome hurdles when I'm writing something new [once a year, if that]. I've never made the time to sit down & study VBA properly [or PowerShell].


    All the best,
    Denis
    Last edited by Try3; 30 Mar 2023 at 09:57.
      My Computer


  6. Posts : 955
    Windows 10 x64
    Thread Starter
       #6

    Thank you very much indeed for your elaborate reply. Truly appreciated!!

    I just read it but also I just found a VBA-macro. Finally, after checking I-don't-know-how-many sites.

    See

    Outlook VBA Save Email Attachments with Received Time and Sender Name

    Written by Graham Mayor.
    Graham Mayor - Home Page

    The only thing I needed to do is the adjust the output folder and changed the 'received time' to format : ddmmyyyy hhmmss

    The file reads (for instance)
    10032023 162523_John Doe_Filename.mp4

    You can select a specific emails, run the macro, it will not run save all attachments of all emails within an account, only the ones you selected.

    Great macro.

    Tried to paste the macro here, but when sending I was blocked.

    you can find it on the above forum though.

    Anyway, try3, all that said, I do appreciate your reply, don't misunderstand.
      My Computer


  7. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #7

    I know the name Graham Mayer and have found his guidance to be very reliable.

    I think yyyymmdd hhmmss is a better sequence to use but it's up to you.
    - yyyymmdd hhmmss is biggest unit through to smallest unit, just like numbers.
    - If you ever want to sort those saved attachment files into email-received date order irrespective of date last modified [i.e. saved to file date in your current case] then ddmmyyyy cannot do that.

    All the best,
    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:10.
Find Us




Windows 10 Forums