Reply to email with message chain below

Alan_CT06

New Member
Joined
Nov 6, 2023
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
HI All,

I want to write VBA code that will reply to an email and include the previous messages below.

I want it to work the same as just clicking the reply button, where all the previous message with the same formatting are displayed below my reply.

My current code is below:

I used the line " .Body = "My Text." & vbCrLf & vbCrLf & vbCrLf & SelectedEmail.Body" to try to include the previous messages, but it doesn't keep the formatting of the previous messages as does clicking Outlook's "Reply" button.

Thanks,
Alan

>>>>>
Sub ReplyEmail()

Dim OutlookApp As Object
Dim OutlookNamespace As Object
Dim CurrentExplorer As Object
Dim SelectedEmail As Object
Dim ForwardedEmail As Object
Dim ReplyEmail As Object


' Create Outlook application object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set CurrentExplorer = OutlookApp.ActiveExplorer

' Check if there is an active email selected
If CurrentExplorer.Selection.Count > 0 Then
Set SelectedEmail = CurrentExplorer.Selection.Item(1)

' Reply to the selected email

Set ReplyEmail = SelectedEmail.Reply
With ReplyEmail
.Body = "My Text." & vbCrLf & vbCrLf & vbCrLf & SelectedEmail.Body
.Display ' Use .Send to send the email directly

End With
Else
MsgBox "No email selected.", vbExclamation
End If

' Clean up
Set ReplyEmail = Nothing
Set SelectedEmail = Nothing
Set CurrentExplorer = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub
>>>
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I used the line " .Body = "My Text." & vbCrLf & vbCrLf & vbCrLf & SelectedEmail.Body" to try to include the previous messages, but it doesn't keep the formatting of the previous messages as does clicking Outlook's "Reply" button.

Try:

VBA Code:
            .HTMLBody = "My Text." & vbCrLf & vbCrLf & vbCrLf & .HTMLBody
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top