Hey guys, I have code that is trying to open a word document and paste it into an email body. If I use plain old control v it works fine but using the method below, I loose my images and my formatting. Is there a way to use sendkeys here or someother method to preserve my formatting when getting the text to the body of the email?
Code:
Private Sub DREmail_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim attachmentQ As String
Dim oWord As Object
Dim wdapp As Word.Application
Dim DRloc As String
Dim DRText As DataObject
With Application
.EnableEvents = False
.ScreenUpdating = True
End With
attachmentQ = MsgBox("Would you like to send this as an attachment? If you select 'No' the body will contain the actual Deployment Recommendation language, rather than be attached.", vbYesNo)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ""
.CC = "christopher.foye@aurorabankfsb.com;patrick.jesienouski@aurorabankfsb.com;joesph.liermo@aurorabankfsb.com"
.Subject = "User Acceptance Testing Deployment Recommendation - " & Sheets("iLead Data").Cells(3, 2)
If attachmentQ = vbNo Then
Set wdapp = New Word.Application
DRloc = Sheets("ilead data").Cells(34, 2)
wdapp.Documents.Open (DRloc)
wdapp.Selection.WholeStory
wdapp.Selection.Copy
Set DRText = New DataObject
DRText.GetFromClipboard
.body = DRText.GetText(1)
wdapp.Quit
Else
.body = "Please see the attached Deployment Recommendation."
.attachments.Add Sheets("iLead Data").Cells(34, 2).Value
End If
.SentOnBehalfOfName = "Aurora UAT Department"
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub