none
use Microsoft VBA to Reply with attachments automatically in outlook RRS feed

  • 问题

  •    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 in the mail body. It report an error:


    click 调试 


    How to fix this problem?

    2018年6月5日 2:11