Copy all Contents from Word Document in same format to outlook Email Body

kshitij_dch

Active Member
Joined
Apr 1, 2012
Messages
362
Office Version
  1. 365
  2. 2016
  3. 2007
Platform
  1. Windows
Hello All,
I am working on a macro which will Copy all Contents from Word Document in same format to outlook Email Body ,I have managed to get a code which is pasting data from excel as string only but not in a same format of word , any chance if i can get it in exact format that of word document ???

VBA 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:\Users\Sony\Desktop\Document.docx", ReadOnly:=True)
    
    'Copy the open document
    doc.Content.Select
    Word.Selection.Copy
    
    Set oItem = oOutlookApp.CreateItem(olMailItem)
    With oItem
        .To = "this@email.com"
        .Subject = "K****ij Sharma"
        .Body = Word.Selection
        .Display
    End With
    
    doc.Close
    wd.Quit
    
    Set doc = Nothing
    Set oItem = Nothing
    Set oOutlookApp = Nothing
    Set wd = Nothing
End Sub
??
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
See if this will help

Hello Dave

I have checked this piece of Code from the above URL however not working

VBA Code:
Sub emailFromDoc()
    Dim wd As Object, editor As Object
    Dim doc As Object
    Dim oMail As MailItem

    Set wd = CreateObject("Word.Application")
    Set doc = wd.documents.Open(...path to your doc...)
    doc.Content.Copy
    doc.Close
    set wd = Nothing

    Set oMail = Application.CreateItem(olMailItem)
    With oMail
        .BodyFormat = olFormatRichText
        Set editor = .GetInspector.WordEditor
        editor.Content.Paste
        .Display
    End With
End Sub

i am getting error on "Set oMail = Application.CreateItem(olMailItem)" Error : Object dosen't support this property or method , can you help in this ??
 
Upvote 0
Do note that the only way to truly replicate the document layout in your email is to attach it; emails don't support headers, footer, footnotes, endnotes and a myriad of other features found in typical Word documents. Moreover, you have no control over any pagination features, or where images etc. will end up, etc. when viewed by the recipient.
 
Upvote 0
Replace:

Code:
     Set oMail = Application.CreateItem(olMailItem)
with
     Set OutApp = CreateObject("Outlook.Application")
     Set oMail = OutApp.CreateItem(0)
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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