Document Content to Body of Email

jonnyp138

Board Regular
Joined
May 2, 2015
Messages
50
Good morning,

Hoping all you wonderful folks out there can help me, I am trying to find a vba script to open a word document and copy the contents and create a new email message and use the document contents as the email body, is this possible using vba?

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Edit - This would need to keep the Word formatting rather than just copy the text over

Formatting in Outlook does have most the same elements as Word but not all.
Why not Share the Word document by Email?
 
Upvote 0
The email is an escalation email and they just want the content of the word template inserting into the body of the email if that makes sense
 
Upvote 0
Formatting in Outlook does have most the same elements as Word but not all.
Why not Share the Word document by Email?

Formatting in Outlook does have most the same elements as Word but not all.
Why not Share the Word document by Email?

I have found the following which seems to work but if it is ran more than once i.e in a loop until all escalations have been dealt with then the 2nd time round I get a runtime error saying the document is locked for editing and cant figure out why?

Set oWordApp = CreateObject("Word.Application")
Set oWordDoc = oWordApp.Documents.Open("C:\Temp\Reminder.docx", ReadOnly:=True)


oWordDoc.Content.Copy
Set oOutApp = CreateObject("Outlook.Application")
Set oMailItem = oOutApp.CreateItem(0)


With oMailItem
.To = ""
.Subject = "Level 2 On Hold Escalation Email"
.Display
End With


Set oMailWordDoc = oOutApp.ActiveInspector.WordEditor


oMailWordDoc.Application.Selection.Paste

oWordApp.Quit
Set oMailItem = Nothing
Set oMailWordDoc = Nothing
Set oOutApp = Nothing
 
Upvote 0
If the content is static and just written up in a Word Document, it might be simpler to make that text an Auto Text or Quick Part.

As far as the error in the loop, it appears it is trying to re-open the Word document. Open the Word document before the Loop and make sure you .Close the document before the procedure finishes. Having to Open/Close it will slow it down if you have a lot of loop executions.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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