More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 23-May-2019 09:50

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Code level: intermediate    Code area: Basic Outlook Printer Friendly Version
Title: Reply with Attachments
Description: This Outlook VBA sample creates and displays a reply to the currently open or selected message including the attachments in the original.
Date: 07-Apr-2006  13:17
Code level: intermediate
Code area: Basic Outlook
Posted by: Sue Mosher
This message is displayed as VB.NET
 Sub ReplyWithAttachments()
    Dim rpl As Outlook.MailItem
    Dim itm As Object
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.Reply
        CopyAttachments itm, rpl
    End If
    Set rpl = Nothing
    Set itm = Nothing
End Sub

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    Set objApp = Nothing
End Function

Sub CopyAttachments(objSourceItem, objTargetItem)
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
   strPath = fldTemp.Path & "\"
   For Each objAtt In objSourceItem.Attachments
      strFile = strPath & objAtt.FileName
      objAtt.SaveAsFile strFile
      objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
      fso.DeleteFile strFile

   Set fldTemp = Nothing
   Set fso = Nothing
End Sub

All 123comments
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>  
  07-Apr-2006  13:19   
Notes on the code:

1) Uses the GetCurrentItem() function from to return the currently selected or displayed item.

2) Uses the CopyAttachments() procedure from to copy the attachments to the reply.

3) Replace itm.Reply with itm.ReplyAll if you prefer to reply to all.
  07-Apr-2006  18:11   
Most excellent, Thank you...
  06-Jun-2006  22:23   
Hail to Sue Mosher - this is a big time & pain saver
  15-Jun-2006  13:14   
OMG, this rocks! I have been looking everywhere for something like this!

Thank you! Thank you! Thank you!
  25-Jul-2006  11:29   
This is great! One little annoyance, though...Is there any way to keep it from copying the background image as an attachment as well?
  25-Jul-2006  12:12   
Leah Ann, the easy solution would be to check the file extension and not copy any images.
  25-Jul-2006  15:01   
This is fabulous! Our users will be thrilled! However, this doesn't seem to work on "reply to all". Should it?
  25-Jul-2006  16:31   
Chelsi, look at the code. The statement that creates the reply is:

    Set rpl = itm.Reply

You could certainly change it to ReplyAll if you wanted to.
  27-Jul-2006  09:06   
You're very kind to share your tips with us! Thank you!
  15-Aug-2006  05:06   
Can't thank-you enough, the code works a treat !
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>