Outlook Reply with Attachments | VBA Macro #62

Share on facebook
Share on twitter
Share on linkedin
If you are responding to someone that has included email attachments when you click Reply or Reply All you will notice the attachments the sender included are not in your respond. While you can simply drag and drop the attachments the sender sent into your response this takes time away from typing a reply. The attachments the sender sent maybe irrelevant to you but important to others so they should continue to be attached in the email thread. Fortunately, there is a better way with VBA and the below macro will allow you Reply and Reply All to an email with the attachments automatically attached in your response. You can create new custom Reply and Reply All with Attachment(s) buttons or embed VBA code behind the current Reply and Reply All buttons to adjust Outlook’s default behavior to start attaching attachments in responses automatically.

See it in Action!

Watch this video to see this macro in action.

***Video coming soon!***

The Code

Here is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Outlook 16.0 Object Library, Microsoft Office 16.0 Object Library, Microsoft Word 16.0 Object Library
Copy the Code
'Leverage & Lean "Less Clicks, More Results"
Sub ReplywithAttachments()
' Means variable is in use
Dim Attachment As Variant '
Dim Attachments() As String '
Dim EmailCurrent As Outlook.MailItem '
Dim fso As Object '
Dim objAttachment As Object '
Dim ReplyAttachments As String '
Dim TempFolder As Object '
  
On Error GoTo LeverageLean
  
Set EmailCurrent = Application.ActiveExplorer.Selection.Item(1) 'Select the Current Unopen Email

If EmailCurrent.Attachments.Count > 0 Then 'If Attachments Exist on the Appointment
Set fso = CreateObject("Scripting.FileSystemObject") 'Set fso
Set TempFolder = fso.GetSpecialFolder(2)
For Each objAttachment In EmailCurrent.Attachments
objAttachment.SaveAsFile TempFolder.Path & "\" & objAttachment.fileName 'Save the Attachment to the Temporary Folder
If ReplyAttachments = "" Then
ReplyAttachments = TempFolder.Path & "\" & objAttachment.fileName
ElseIf ReplyAttachments <> "" Then
ReplyAttachments = ReplyAttachments & ";" & TempFolder.Path & "\" & objAttachment.fileName
End If
Next
End If
Set EmailCurrent = EmailCurrent.Reply 'If you want to Reply with Attachments
'Set EmailCurrent = EmailCurrent.ReplyAll 'If you want to ReplyAll with Attachments
Attachments = Split(ReplyAttachments, ";")
For Each Attachment In Attachments
EmailCurrent.Attachments.Add Attachment 'Add Attachment to Email
fso.DeleteFile Attachment 'Delete the Attachment in the Temporary Folder
Next
EmailCurrent.Display
  
Set EmailCurrent = Nothing
Set fso = Nothing
Set objAttachment = Nothing
Set TempFolder = Nothing
  
Exit Sub
   
LeverageLean:
EmailCurrent.Display
MsgBox (Err.Number & " - " & Err.Description & vbNewLine & vbNewLine & "Don't hesitate to email me: brentschneider@leveragelean.com")
Exit Sub
   
End Sub
'Stay Awesome
Although you can create a custom button to trigger the Reply and Reply All with Attachments macro on command you can also adjust the default behavior of Outlook’s current Reply and Reply All buttons with some additional VBA code.

Here is the additional code that can you used to fire this macro with Outlook’s Reply and Reply All buttons. Copy and Paste this VBA code into your Outlook Session and restart Outlook.
Copy the Code
'Leverage & Lean "Less Clicks, More Results"
Option Explicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Dim bDiscardEvents As Boolean
Private Sub Application_Startup()
Set oExpl = Application.ActiveExplorer
bDiscardEvents = False

'Call the Macros listed below:
'Call MacroName
   
End Sub
Private Sub oExpl_SelectionChange()
On Error Resume Next
Set oItem = oExpl.Selection.Item(1)
End Sub
Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
On Error GoTo LeverageLean
Cancel = True
bDiscardEvents = True

'Call the Macros listed below:
Call ReplywithAttachments

Exit Sub

LeverageLean:

End Sub
Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
On Error GoTo LeverageLean
Cancel = True
bDiscardEvents = True

'Call the Macros listed below:
Call ReplyAllwithAttachments

Exit Sub

LeverageLean:

End Sub
'Stay Awesome!

First time using VBA?

The Developer Tab is an additional section of the ribbon when activated allows you access to Visual Basic in Applications like Access, Excel, Outlook, PowerPoint, Word.
Setup Now
Once the Developer Tab is available you will have the capability to update your security to allow Macros to run in the current application.
Setup Now
A sub of code is a collection of objects and variables. For the code to successfully run a library of references needs to be set.
Setup Now
Subscribe as an Insider to receive additional rights.
If you like our content and want to show your support tip us here!

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Leverage & Lean

Is focused on improving computer processes by Leveraging programming and applying Lean principles. It is our goal to make you more efficient and effective on your computer producing “Less Clicks and More Results!”