Search code examples
excelvbaoutlookemail-attachments

Save a copy of the current attachment before sending


How do I save a copy of attachment I just attached before I send as a backup.

Any help would be great! Thank you.

    Dim outlookOBJ As Object
    Dim MItem As Object

   Set outlookOBJ = CreateObject("Outlook.Application")
   Set MItem = outlookOBJ.CreateItem(olMailItem)
   With MItem
   .To = "email1@gmail.com"
  '.cc = "email2@gmail.com"
   .Subject = " Test Subject"
   .body = " test text in body of email" & Me.EvalID_T1.Value
   .Attachments.Add (ActiveWorkbook.Worksheets("BrowseFile").Cells(4,3).Value)
   'want to add some kind of save current attachment feature here right before I send

    .send

Solution

  • Simply use For Each … In … Next Loop to save current MItem.Attachments

    With MItem
        .To = "email1@gmail.com"
        '.cc = "email2@gmail.com"
        .Subject = " Test Subject"
        .Body = " test text in body of email" & Me.EvalID_T1.value
        .Attachments.Add (ActiveWorkbook.Worksheets("BrowseFile").Cells(4, 3).value)
    
         Dim Atmt As Object
         For Each Atmt In MItem.Attachments
             Debug.Print Atmt.DisplayName
             Atmt.SaveAsFile "C:\Temp\" & Atmt.DisplayName
         Next
    
        .Display
    End With