none
Rename attachment in Outlook RRS feed

  • Question

  • Hallo,

    I have rules and script in Outlook to save attachment:

    Sub SaveAttachments2(myMail As MailItem)
    Dim vFrom As String, vSubject As String
    Dim vFile As Attachment
     
    vFrom = myMail.ReceivedByName
    vSubject = myMail.Subject
     
    If myMail.Attachments.Count > 0 Then
            For i = 1 To myMail.Attachments.Count
                Set vFile = myMail.Attachments(i)
                If LCase(vFile.FileName) Like "*.png" Then
                vFile.SaveAsFile "C:\ris\" & vFile.FileName
                End If
            Next i
    End If
     
    
    Set myMail = Nothing
    Set vFile = Nothing
    End Sub

    This works.
    But all attachments have same name "untitled.png"and dont save more files to same folder.

    How to add to script function to rename file by date and time before save to folder, example "untitled180413_092400.png"?

    Thank You

    Friday, April 13, 2018 7:27 AM

Answers

  • This works

    Sub SaveAttachments2(myMail As MailItem)
    Dim Datum As Date, Citac As Long
      With myMail
        Datum = .LastModificationTime
        For i = 1 To .Attachments.Count
          With .Attachments(i)
            If Right$(LCase(.FileName), 4) = ".png" Then
              Citac = Citac + 1
              .SaveAsFile "C:\ris\" & Replace(.FileName, ".png", Format(Datum, "yymmdd_hhmmss") & "_" & Citac & ".png")
            End If
          End With
        Next i
      End With
    End Sub

    • Marked as answer by Tomdouda Friday, April 13, 2018 10:07 AM
    Friday, April 13, 2018 10:07 AM