Document Content to Body of Email

jonnyp138

Board Regular
Joined
May 2, 2015
Messages
50
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Edit - This would need to keep the Word formatting rather than just copy the text over
 
Upvote 0
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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