PDA

View Full Version : sub to reply, add CC and content but loses original message and HTML formating.



namy77
09-21-2016, 01:50 PM
Good afternoon,

I currently use this code to reply to a selected email, add a CC address, attach the original message and add some predetermined text in the response:




Sub Redirect()


Dim mymail As Outlook.MailItem


Dim myReply As Outlook.MailItem


Dim numItems As Integer


Set mySelected = Outlook.ActiveExplorer.Selection


numItems = mySelected.Count


For i = 1 To numItems


Set mymail = mySelected(1)


Set myReply = mymail.Reply


mytext = myReply.Body


With myReply




mytext = "Hello," & vbCrLf


mytext = mytext & vbCrLf & "I have received your request and forwarded it to Blah Blah, who will handle it from here."








End With




myReply.Body = mytext
Dim Reply As Outlook.MailItem
Dim Original As Outlook.MailItem
Set Original = Application.ActiveExplorer.Selection(1)
Set Reply = Original.Reply
myReply.Attachments.Add Original
myReply.Recipients.Add "email address"


myReply.Display






Set mymail = Nothing


Set myReply = Nothing


Next


Set mySelected = Nothing


End Sub

My only issues are that the response text is not in HTML format, I lost my signature and the original content is not underneath my signature any more.

Anybody has a solution? I would really appreciate the help!

skatonni
09-21-2016, 03:24 PM
This replaces the body

myReply.Body = mytext

Instead try



myReply.Display ' This generates the signature

myReply.HTMLBody = mytext & myReply.HTMLBody

gmayor
09-21-2016, 10:21 PM
Personally I would take a different approach:

Option Explicit

Sub Redirect()
Dim myMail As Outlook.MailItem
Dim myReply As Outlook.MailItem
Dim mySelected As Outlook.Selection
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim i As Long
Dim myText As String
myText = "Hello," & vbCrLf
myText = myText & vbCrLf & "I have received your request and forwarded it to Blah Blah, who will handle it from here."
Set mySelected = Outlook.ActiveExplorer.Selection
For i = 1 To mySelected.Count
Set myMail = mySelected(i)
Set myReply = Outlook.CreateItem(olMailItem)
With myReply
.BodyFormat = olFormatHTML
.To = myMail.SenderEmailAddress
.subject = "Re: " & myMail.subject
'blind copy to the person it was forwarded to
.Recipients.Add("someone@somewhere.com").Type = 3
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range(0, 0)
.Display
oRng.Text = myText
.Attachments.Add myMail
End With
Next i
lbl_Exit:
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Set myMail = Nothing
Set myReply = Nothing
Set mySelected = Nothing
Exit Sub
End Sub