Copying from Word to Email via Excel VBA

cfoye130

Board Regular
Joined
Aug 12, 2008
Messages
84
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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How big is the information in the Word doc?
If it's not too big can you recreate it in HTML then use the HTMLBody instead of Body to just put it in the email?
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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