Results 1 to 7 of 7

Thread: attach attachments from an existing email when a reply all is executed

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Regular
    Joined
    May 2018
    Location
    Sydney
    Posts
    57
    Location
    Quote Originally Posted by hrq View Post
    Hi All

    I would like to attach attachments from an existing email when a reply all is executed without the need to save the attachment into a specific folder. I tried using the following code but it populates an error run time 438. Is there a way to fix this?

    The macro is executed from excel.

    Set myAttachment = Item.Attachments                
    Set OutMail = Item.ReplyAll
    If myAttachment.Count >= 1 Then
    With OutMail
    .HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
     .Attachments.Add myAttachment
    .Display
    '.Send
    End With
    Else
    With OutMail
    .HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
    .Display
    '.Send
    End With
    End If
    To attach attachments from an existing email when a reply all is executed using VBA, you can use the Attachments property of the MailItem object, which represents an email message.

    Here is an example of how you can do this:
    Sub ReplyAllWithAttachments()
        Dim objOutlook As Outlook.Application
        Set objOutlook = New Outlook.Application
    ' Get the currently selected email in Outlook
        Dim objMail As Outlook.MailItem
        Set objMail = objOutlook.ActiveExplorer.Selection.Item(1)
    ' Create a new email for the reply
        Dim objReply As Outlook.MailItem
        Set objReply = objMail.ReplyAll
    ' Loop through the attachments in the original email
        Dim objAttachment As Outlook.Attachment
        For Each objAttachment In objMail.Attachments
            ' Attach each attachment to the reply email
            objReply.Attachments.Add objAttachment
        Next objAttachment
    ' Show the reply email so the user can edit it and send it
        objReply.Display
    End Sub
    Last edited by Aussiebear; 12-09-2022 at 03:29 AM. Reason: Added code tags to supplied code
    If you only ever do what you can , you'll only ever be what you are.

Tags for this Thread

Posting Permissions

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