Consulting

Results 1 to 5 of 5

Thread: With used macro the saved date is incorrect, how can I make sure this is correct?

  1. #1

    With used macro the saved date is incorrect, how can I make sure this is correct?

    Hi,

    I use the macro below to save a selection of e-mail attachements. (thanks to gmayor)

    Option Explicit 
    Public Sub saveAttachToDisk()
         
        Dim objAtt As Outlook.Attachment
        Dim olMsg As Outlook.MailItem
        Dim strDate As String
        Dim strName As String
        Dim lngAns As Long
        Dim oFrm As UserForm1
        Const saveFolder1 As String = "C:\Temp\Test1\"
        Const saveFolder2 As String = "C:\Temp\Test2\"
        Const saveFolder3 As String = "C:\Temp\Test3\"
         
         
        On Error Resume Next
        Set olMsg = ActiveExplorer.Selection.Item(1)
        strDate = Format(Now, " yyyy-mm-dd")
        For Each objAtt In olMsg.Attachments
                Set oFrm = New UserForm1
                With oFrm
                    .Caption = "Select Save Option"
                    .CommandButton1.Caption = "Doorgaan"
                    .CommandButton2.Caption = "Opslaan afbreken"
                    .TextBox1.Text = objAtt.FileName
                    .OptionButton1.Caption = "Opslaan in Verkooporders"
                    .OptionButton2.Caption = "Customer 1"
                    .OptionButton3.Caption = "Customer 1"
                    .OptionButton4.Caption = "Niet opslaan"
                    .OptionButton4.Value = True
                    .Show
                    If .Tag = 0 Then GoTo lbl_Exit
                    strName = oFrm.TextBox1.Text
                    Select Case True
                    Case Is = .OptionButton1.Value
                        objAtt.SaveAsFile saveFolder1 & strName
                    Case Is = .OptionButton2.Value
                        objAtt.SaveAsFile saveFolder2 & strName
                    Case Is = .OptionButton3.Value
                        objAtt.SaveAsFile saveFolder3 & strName
                    Case Else
                    End Select
                End With
                Unload oFrm
        Next objAtt
    lbl_Exit:
        Set oFrm = Nothing
        Set objAtt = Nothing
        Set olMsg = Nothing
        Exit Sub
    End Sub
    The code works perfectly, but the saved date (see picture below) is the date and time the e-mail was send instead of the date and time the file was saved.
    Is it possible to use the date and time of the moment of saving instead of the moment the e-mail was send?

    28-4-2017 8-06-22.jpg
    Thanks

    Grtz WillemKanon

  2. #2
    The code you have listed includes a variable strDate which is the date now
    strDate = Format(Now, " yyyy-mm-dd")
    This isn't used in the macro, but can be added to the filename e.g.
    strName = strDate & Chr(32) & oFrm.TextBox1.Text
    If you save an attachment, the filedate should be the sate it was saved.

    e.g. I saved the following attachment a few minutes ago:

    2017-04-28_15-50-53.jpg
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    I changed the code to use the strDate
    and tried to save another document to see what the date is
    28-4-2017 15-14-22.jpg

    as you can see it is still the time at which the mail was send.
    maybe you tried the code with an e-mail that was just send?

  4. #4
    Hi,

    I read on another forum that SetFileDateTime could be the solution to the problem.
    Unfortunately, I cannot build this into my code myself because I'm not that good at writing code.

    Is there anyone who could try this for me?

    Thanks

  5. #5
    >>The question is solved on another forum<<

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •