PDA

View Full Version : [SOLVED:] Word to Outlook, sending document contents to body of email



Guyver4
05-16-2024, 07:56 AM
Hello guys

I am wondering if you can help me with this?

I have found this code example below, while it saves the contents of the document as a PDF attachement and sends to outlook, what I would like to do is simply transfer the contents of the document to the body of the email instead. I have played around with it, but cannot figure it out. Thanks.


Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
Doc.Content.Copy
With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & "Line 3"
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

Aussiebear
05-16-2024, 01:29 PM
Have you tried this?


Sub emailFromDoc()
Dim wd As Object, editor As Object
Dim doc As Object
Dim oMail As MailItem
Set[ wd = CreateObject("Word.Application")
Set doc = wd.documents.Open(...path to your doc...)
doc.Content.Copy
doc.Close
Set wd = Nothing
Set oMail = Application.CreateItem(olMailItem)
With oMail
.BodyFormat = olFormatRichText
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
End With
End Sub

Guyver4
05-20-2024, 02:38 PM
Hello Aussiebear

Sorry for the late reply. Thanks for the example, I did find another solution in the end. I will post it if anyone is interested.



Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim oEditor As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
Doc.Content.Copy
With EmailItem
.Subject = "Insert Subject Here"
.BodyFormat = olFormatRichText
Set oEditor = .GetInspector.WordEditor
oEditor.Content.Paste
.To = "user@example.com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Display 'Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

inkaterу
07-04-2024, 03:20 AM
Trying to integrate document contents directly into Outlook emails can be a bit tricky. From what I've tinkered with, modifying the code to transfer document contents to the email body instead of attaching as a PDF involves adjusting how the Doc.Content.Copy is handled.

inkaterу
07-10-2024, 07:21 AM
Trying to integrate document contents directly into Outlook emails can be a bit tricky. From what I've tinkered with, modifying the code to transfer document contents to the email body instead of attaching as a PDF involves adjusting how the Doc.Content.Copy is handled.

You might need to experiment with pasting the content directly into .Body instead of using .Attachments.Add.