PDA

View Full Version : [SOLVED:] attach attachments from an existing email when a reply all is executed



hrq
12-06-2022, 08:40 PM
Hi All

I would like to attach attachments from an existing email when a reply all is executed without the need to save the attachment into a specific folder. I tried using the following code but it populates an error run time 438. Is there a way to fix this?

The macro is executed from excel.



Set myAttachment = Item.Attachments
Set OutMail = Item.ReplyAll

If myAttachment.Count >= 1 Then

With OutMail
.HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
.Attachments.Add myAttachment
.Display
'.Send
End With

Else

With OutMail
.HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
.Display
'.Send
End With

End If

June7
12-06-2022, 11:14 PM
I don't think can avoid first saving out to folder.

hrq
12-06-2022, 11:34 PM
oh mann.. anyways thanks for the help.

Grade4.2
12-09-2022, 12:34 AM
Hi All

I would like to attach attachments from an existing email when a reply all is executed without the need to save the attachment into a specific folder. I tried using the following code but it populates an error run time 438. Is there a way to fix this?

The macro is executed from excel.



Set myAttachment = Item.Attachments
Set OutMail = Item.ReplyAll
If myAttachment.Count >= 1 Then
With OutMail
.HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
.Attachments.Add myAttachment
.Display
'.Send
End With
Else
With OutMail
.HTMLBody = "Hi Siew Ping, <p> $" & strPayment & " received On the " & strPaymentdate & " .<p> Thanks & Regards," & .HTMLBody
.Display
'.Send
End With
End If


To attach attachments from an existing email when a reply all is executed using VBA, you can use the Attachments property of the MailItem object, which represents an email message.

Here is an example of how you can do this:

Sub ReplyAllWithAttachments()
Dim objOutlook As Outlook.Application
Set objOutlook = New Outlook.Application
' Get the currently selected email in Outlook
Dim objMail As Outlook.MailItem
Set objMail = objOutlook.ActiveExplorer.Selection.Item(1)
' Create a new email for the reply
Dim objReply As Outlook.MailItem
Set objReply = objMail.ReplyAll
' Loop through the attachments in the original email
Dim objAttachment As Outlook.Attachment
For Each objAttachment In objMail.Attachments
' Attach each attachment to the reply email
objReply.Attachments.Add objAttachment
Next objAttachment
' Show the reply email so the user can edit it and send it
objReply.Display
End Sub

June7
12-09-2022, 10:30 PM
Okay, looks like I was wrong. Hope OP comes back to view.

Grade4.2
12-10-2022, 07:18 PM
After testing the code I realized I made a mistake. I had a similar macro that I modified without any syntax errors which lead me to believe it was the right code.

I apologize for any inconvenience caused.

hrq
12-12-2022, 01:30 AM
After testing the code I realized I made a mistake. I had a similar macro that I modified without any syntax errors which lead me to believe it was the right code.

I apologize for any inconvenience caused.

no worries man! appreciate the effort. I heed June7's advice by creating a folder for it. And it works perfectly.