Use excel to copy word file to outlook as body of email

Status
Not open for further replies.

tomhow

New Member
Joined
Sep 24, 2017
Messages
7
I am trying to createa macro in excel which will send an email to a large number of people bycopying the contents of a word file as the body of the email. The list of emailaddresses is listed in column A of sheet1. I modified the code below from a post I found earlier. My problem istwofold; firstly when I run it, the macro hangs and I get a message that thedocument is locked for editing by XXX and do I want to open it as readonly. This is despite the fact that thedocument is not open nor is Word running. Secondly, I get a run time 91 Error “Object variable orwith block variable not set” The problem line is:
Set oMailWordDoc =oOutApp.ActiveInspector.WordEditor
Could someone pleasegive me the benefit of their expertise? I am running excel, word & outlook2010.

Code:
Sub CopyBodyFromWord()

Dim oOutApp As Object
Dim oMailItem As Object
Dim oWordApp As Object
Dim oWordDoc As Object
Dim oMailWordDoc As Object
Dim WDocName As String
For j = 1 To 3 'use cells 1 to 3 in column "A" as a test run
    If Sheets("SHEET1").Range("A1").Value <> "" Then
        myadd = myadd & ";" & Sheets("SHEET1").Range("A" & j).Value
    End If
Next
On Error GoTo CleanUp
WDocName = InputBox("What is the name of the word file to be copied to the email?")
Set oWordApp = CreateObject("Word.Application")
Set oWordDoc = oWordApp.Documents.Open("C:\Users\Janet & Peter\Documents\" & WDocName)
oWordDoc.Content.Copy
Set oOutApp = CreateObject("Outlook.Application")
Set oMailItem = oOutApp.CreateItem(0)
With oMailItem
    .To = ""
    .Bcc = myadd
    .Subject = "Test Email"
End With
Set oMailWordDoc = oOutApp.ActiveInspector.WordEditor
oMailWordDoc.Application.Selection.Paste
CleanUp:
oWordApp.Quit
Set oMailWordDoc = Nothing
Set oMailItem = Nothing
Set oOutApp = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Status
Not open for further replies.

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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