Witzker
Senior Member
- OS Version(s)
- iOS
- Outlook version
- Outlook 2019 32-bit
- Email Account
- Exchange Server 2007
Hi I need to answer All or ONE sender of email with keeping all attachments in the answer mail.
To do this easy, I found the following macro:
from here: Wie behalte ich Anhänge bei der Beantwortung in Outlook?
I put it in This OL-Session but got the following error
As I'm not clever enough to get this running
I hope for your help.
Or do you have a better solution for this?
Many THX
To do this easy, I found the following macro:
Code:
Sub RunReplyWithAttachments()
'Update by Extendoffice 20180830
Dim xReplyItem As Outlook.MailItem
Dim xItem As Object
On Error Resume Next
Set xItem = GetCurrentItem()
If xItem Is Nothing Then Exit Sub
Set xReplyItem = xItem.Reply
CopyAttachments xItem, xReplyItem
xReplyItem.Display
Set xReplyItem = Nothing
Set xItem = Nothing
End Sub
Sub RunReplyAllWithAttachments()
Dim xReplyAllItem As Outlook.MailItem
Dim xItem As Object
Set xItem = GetCurrentItem()
If xItem Is Nothing Then Exit Sub
Set xReplyAllItem = xItem.ReplyAll
CopyAttachments xItem, xReplyAllItem
xReplyAllItem.Display
Set xReplyAllItem = Nothing
Set xItem = 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(SourceItem As MailItem, TargetItem As MailItem)
Dim xFilePath As String
Dim xAttachment As Attachment
Dim xFSO As Scripting.FileSystemObject
Dim xTmpFolder As Scripting.Folder
Dim xFldPath As String
Set xFSO = New Scripting.FileSystemObject
Set xTmpFolder = xFSO.GetSpecialFolder(2)
xFldPath = xTmpFolder.Path & "\"
For Each xAttachment In SourceItem.Attachments
If IsEmbeddedAttachment(xAttachment) = False Then
xFilePath = xFldPath & xAttachment.Filename
xAttachment.SaveAsFile xFilePath
TargetItem.Attachments.Add xFilePath, , , xAttachment.DisplayName
xFSO.DeleteFile xFilePath
End If
Next
Set xFSO = Nothing
Set xTmpFolder = Nothing
End Sub
Function IsEmbeddedAttachment(Attach As Attachment)
Dim xAttParent As Object
Dim xCID As String, xID As String
Dim xHTML As String
On Error Resume Next
Set xAttParent = Attach.Parent
xCID = ""
xCID = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCID <> "" Then
xHTML = xAttParent.HTMLBody
xID = "cid:" & xCID
If InStr(xHTML, xID) > 0 Then
IsEmbeddedAttachment = True
Else
IsEmbeddedAttachment = False
End If
End If
End Function
from here: Wie behalte ich Anhänge bei der Beantwortung in Outlook?
I put it in This OL-Session but got the following error
As I'm not clever enough to get this running
I hope for your help.
Or do you have a better solution for this?
Many THX