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?
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)
Set oOutApp = CreateObject("Outlook.Application")
Set oMailItem = oOutApp.CreateItem(0)
.To = ""
.Subject = "Level 2 On Hold Escalation Email"
Set oMailWordDoc = oOutApp.ActiveInspector.WordEditor
Set oMailItem = Nothing
Set oMailWordDoc = Nothing
Set oOutApp = Nothing
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.