Send Word Document As Body of Email

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
I am trying to send a Word Document as the body of an email. This is what I have from another post. I tried to add a:

Dim outlook as Outlook.Application

but I also am confused about you can use the "doc", a Word.Document, in the same statement as an Outlook.MailItem?

Set itm = doc.MailEnvelope.Item

Code:
Sub SendDocAsMsg()
    Dim wd As Word.Application
    Dim doc As Word.Document
    Dim itm As Outlook.MailItem
    Dim ID As String
    Dim blnWeOpenedWord As Boolean
    
    Set wd = CreateObject("Word.Application")
    
    wd.Visible = True
    
    Set doc = wd.Documents.Open(Filename:="C:\Users\this\toEmail.doc", ReadOnly:=True)
    Set itm = doc.MailEnvelope.Item
    With itm
        .To = "[EMAIL="this@email"]this@email[/EMAIL].com"
        .Subject = "My Subject"
        .Send
    End With
    
    doc.Close
    wd.Quit
  
    Set doc = Nothing
    Set itm = Nothing
    Set wd = Nothing
    
End Sub

Add two references: Word and Outlook.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The getting the email and word document works. I can not figure out how to get the copied doc to display on the body of the email.


Code:
Sub SendDocAsMsg()
    Dim wd As Word.Application
    Dim doc As Word.Document
    Dim ID As String
    Dim blnWeOpenedWord As Boolean
    Dim oOutlookApp As Outlook.Application
    Dim oItem As Outlook.MailItem
    On Error Resume Next
    'Start Outlook if it isn't running
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set oOutlookApp = CreateObject("Outlook.Application")
    End If
    
    
    Set wd = CreateObject("Word.Application")
    
    wd.Visible = True
    
Set doc = wd.Documents.Open(Filename:="C:\path\file.doc", ReadOnly:=True)
'Copy the open document
Selection.WholeStory
Selection.Copy
Selection.End = True
   Set oItem = oOutlookApp.CreateItem(olMailItem)
    With oItem
        .To = "[EMAIL="this@email.com"]this@email.com[/EMAIL]"
        .Subject = "My Subject"
        .Body = Selection.Paste 'This does not work
        .Send
    End With
    
    doc.Close
    wd.Quit
    
    Set doc = Nothing
    Set oItem = Nothing
    Set oOutlookApp = Nothing
    Set wd = Nothing
End Sub
 
Upvote 0
This works for me.
Code:
Sub SendDocAsMsg()
    Dim wd As Word.Application
    Dim doc As Word.Document
    Dim oOutlookApp As Outlook.Application
    Dim oItem As Outlook.MailItem
    
    On Error Resume Next
    'Start Outlook if it isn't running
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set oOutlookApp = CreateObject("Outlook.Application")
    End If
    On Error GoTo 0
    
    Set wd = CreateObject("Word.Application")
    
    wd.Visible = True
    
    Set doc = wd.Documents.Open(Filename:="C:\path\file.doc", ReadOnly:=True)
    
    'Copy the open document
    doc.Content.Select
    Word.Selection.Copy
    
    Set oItem = oOutlookApp.CreateItem(olMailItem)
    With oItem
        .To = "this@email.com"
        .Subject = "My Subject"
        .Body = Word.Selection
        .Send
    End With
    
    doc.Close
    wd.Quit
    
    Set doc = Nothing
    Set oItem = Nothing
    Set oOutlookApp = Nothing
    Set wd = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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