none
How To Keep Attachments When Replying In Outlook? RRS feed

  • Question

  • I tried to Reply With Attachments Automatically By VBA 

    There is a VBA macro that can help to reply with original attachments automatically.

    Note: Before you run any VBA macros, you need to enable macros in Microsoft Outlook.

    Step 1: Select the email message that you will reply with its attachments.

    Step 2: Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

    Step 3: Expand the Project1 and Microsoft Outlook Objects in the left bar, and double-click the ThisOutlookSession to open it.

    Step 4: Paste the following code into the ThisOutlookSession window.

    Sub RunReplyWithAttachments()
    Dim oReply As Outlook.MailItem
    Dim oItem As Object
    Set oItem = GetCurrentItem()
    If Not oItem Is Nothing Then
    Set oReply = oItem.Reply
    CopyAttachments oItem, oReply
    oReply.Display
    End If
    Set oReply = Nothing
    Set oItem = Nothing
    End Sub
    Sub RunReplyAllWithAttachments()
    Dim oReply As Outlook.MailItem
    Dim oItem As Object
    Set oItem = GetCurrentItem()
    If Not oItem Is Nothing Then
    Set oReply = oItem.ReplyAll
    CopyAttachments oItem, oReply
    oReply.Display
    End If
    Set oReply = Nothing
    Set oItem = Nothing
    End Sub
    Function GetCurrentItem() As Object
    On Error Resume Next
    Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"
    Set GetCurrentItem = Application.ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set GetCurrentItem = Application.ActiveInspector.CurrentItem
    End Select
    End Function
    Sub CopyAttachments(oSourceItem, oTargetItem)
    Set oFso = CreateObject("Scripting.FileSystemObject")
    Set fldTemp = oFso.GetSpecialFolder(2) 'Temporary Folder
    sPath = fldTemp.Path & "\"
    For Each oAtt In oSourceItem.Attachments
    sFile = sPath & oAtt.FileName
    oAtt.SaveAsFile sFile
    oTargetItem.Attachments.Add sFile, , , oAtt.DisplayName
    oFso.DeleteFile sFile
    Next
    Set fldTemp = Nothing
    Set oFso = Nothing
    End Sub

    Step 5: Press the F5 key to run this macro.

    Then it opens the Replying message window with attaching all of original attachments.

    Step 6: Compose the replying message, and click Send button.

    Notes: If there are pictures existing in your email body, the pictures will be added to the attached field with the original attachments after applying this VBA code.

    But there is a problem when I using this way to reply with attachments.

    When I reply a RTF mail which has a pic(.png) in the mail body. It report an error:

    click 调试

    How to fix this problem?

    • Moved by Steve Fan Monday, June 11, 2018 1:47 AM relocate
    Saturday, June 9, 2018 12:18 PM

All replies

  • Hi,

    Welcome to the Microsoft Office for IT Professionals Outlook forum. This forum is for non-programming questions related to Microsoft outlook. Since your question is more related to VBA, I'll move it to the dedicated Outlook for Developers forum:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding. 

    Regards,
    Steve Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, June 11, 2018 1:47 AM
  • Hello Astraboboy,

    I failed to reproduce your issue. The code works for me to reply mail with attachments.

    Is it related to specific RTF mail or all mails? Could you use it to reply a normal HTML mail?

    What's the attachment? While the error occurs, what's the value of sPath and oAtt.FileName?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 11, 2018 7:25 AM
  • In win 10 the VBA works well, In win 7 it runs error as I showed in the screenshot(when there is a pic in the RTF mail body). When the mail format is HTML or TXT the VBA works well.
    Tuesday, June 12, 2018 3:29 AM
  • Hello Astraboboy,

    I just tried to run the code on Win 7 and I still failed to reproduce the issue.

    What's the attachment? What's the value of the sPath and oAtt.FileName?Would you mind create a test mail and then save it as MSG file and then share the file to us to reproduce your issue?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 12, 2018 6:51 AM
  • ok what's your email address?

    Insert a screenshot of the image in the body of the message, and then use the VBA program to reply with an error message.
    • Edited by Astraboboy Tuesday, June 12, 2018 7:44 AM
    Tuesday, June 12, 2018 7:39 AM
  • Hello Astraboboy,

    For sharing the document, you could share it via cloud storage, such as One Drive, and then put the link address here.

    Thanks for understanding,

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 12, 2018 10:00 AM
  • Hello,

    I could reproduce your issue. Same mail sent from Win 7 and Win 10 give different results. oAtt.FileName give error for mail send from Win7.

    I will suggest you contacting the Microsoft professional support so that our engineers can work closely with you to troubleshoot this issue.

    If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Best Regards,

    tERRY


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 20, 2018 8:46 AM
  • I did more test and find out that it reports an error too when reply RTF mail in win 10,so I think there should be a way to solve this problem by modify the VBA code.
    Tuesday, June 26, 2018 2:48 AM