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
>>>
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
>>>