Consulting

Results 1 to 7 of 7

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

  1. #1
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location

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

    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

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    323
    Location
    I don't think can avoid first saving out to folder.
    How to attach file: How to upload your attachments (vbaexpress.com) To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location
    oh mann.. anyways thanks for the help.

  4. #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.

  5. #5
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    323
    Location
    Okay, looks like I was wrong. Hope OP comes back to view.
    How to attach file: How to upload your attachments (vbaexpress.com) To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    VBAX Regular
    Joined
    May 2018
    Location
    Sydney
    Posts
    57
    Location
    After testing the code I realized I made a mistake. I had a similar macro that I modified without any syntax errors which lead me to believe it was the right code.

    I apologize for any inconvenience caused.

  7. #7
    VBAX Regular
    Joined
    Nov 2022
    Posts
    7
    Location
    Quote Originally Posted by Grade4.2 View Post
    After testing the code I realized I made a mistake. I had a similar macro that I modified without any syntax errors which lead me to believe it was the right code.

    I apologize for any inconvenience caused.
    no worries man! appreciate the effort. I heed June7's advice by creating a folder for it. And it works perfectly.

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
  •