As you know while you are using outlook and use (Reply/ Reply All) to an email message, the original attachments is not included on the replied message.
So, I have used the below code and assigned to a custom buttons on outlook ribbon, and it works correctly.
Instead of click on my custom button, I need to assign my code directly to outlook inbuilt functions itself (Reply and Reply All) .
I found that outlook provides two events for oMailItem Object
oMailItem_Reply and oMailItem_ReplyAll.
I have used it like this:
Private Sub oMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
Call ReplyWithAttachments
End Sub
Private Sub oMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Call ReplyAllWithAttachments
End Sub
But when I click on outlook (Reply and Reply All) itself, then either one from the following behavior happens:
1- a new replied email created without any attachments at all ,
2- Or the new replied email created twice , one with attachments included and the other one without any attachments.
This is the full working code to add the attachments from the original email to the replied one:
Option Explicit
Option Compare Text
Sub ReplyWithAttachments()
ReplyAndAttach (False)
End Sub
Sub ReplyAllWithAttachments()
ReplyAndAttach (True)
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 AddOriginalAttachments(ByVal myItem As Object, ByVal myResponse As Object)
Dim fldTemp As Object, strPath As String, strFile As String
Dim myAttachments As Variant, attach As Attachment
Set myAttachments = myResponse.Attachments
Dim fso As New FileSystemObject
Set fldTemp = fso.GetSpecialFolder(2) 'User Temp Folder
strPath = fldTemp.Path & "\"
For Each attach In myItem.Attachments
If Not attach.FileName Like "*image###.png" And _
Not attach.FileName Like "*image###.jpg" And _
Not attach.FileName Like "*image###.gif" Then
strFile = strPath & attach.FileName
attach.SaveAsFile strFile
myAttachments.Add strFile, , , attach.DisplayName
fso.DeleteFile strFile
End If
Next
Set fldTemp = Nothing
Set fso = Nothing
Set myAttachments = Nothing
End Sub
Sub ReplyAndAttach(ByVal ReplyAll As Boolean)
Dim myItem As Outlook.MailItem
Dim oReply As Outlook.MailItem
Set myItem = GetCurrentItem()
If Not myItem Is Nothing Then
If ReplyAll = False Then
Set oReply = myItem.Reply
Else
Set oReply = myItem.ReplyAll
End If
AddOriginalAttachments myItem, oReply
oReply.Display
myItem.UnRead = False
End If
Set oReply = Nothing
Set myItem = Nothing
End Sub