Consulting

Results 1 to 5 of 5

Thread: Word to Outlook, sending document contents to body of email

  1. #1

    Word to Outlook, sending document contents to body of email

    Hello guys

    I am wondering if you can help me with this?

    I have found this code example below, while it saves the contents of the document as a PDF attachement and sends to outlook, what I would like to do is simply transfer the contents of the document to the body of the email instead. I have played around with it, but cannot figure it out. Thanks.

    Sub eMailActiveDocument()
        Dim OL As Object
        Dim EmailItem As Object
        Dim Doc As Document
        Application.ScreenUpdating = False
        Set OL = CreateObject("Outlook.Application")
        Set EmailItem = OL.CreateItem(olMailItem)
        Set Doc = ActiveDocument
        Doc.Save
        Doc.Content.Copy
        With EmailItem
            .Subject = "Insert Subject Here"
            .Body = "Insert message here" & vbCrLf & _
            "Line 2" & vbCrLf & "Line 3"
            .To = "User@Domain.Com"
            .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
            .Attachments.Add Doc.FullName
            .Send
        End With
        Application.ScreenUpdating = True
        Set Doc = Nothing
        Set OL = Nothing
        Set EmailItem = Nothing
    End Sub

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,217
    Location
    Have you tried this?
    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
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Hello Aussiebear

    Sorry for the late reply. Thanks for the example, I did find another solution in the end. I will post it if anyone is interested.

    Sub eMailActiveDocument()
        Dim OL As Object
        Dim EmailItem As Object
        Dim oEditor As Object
        Dim Doc As Document
        Application.ScreenUpdating = False
        Set OL = CreateObject("Outlook.Application")
        Set EmailItem = OL.CreateItem(olMailItem)
        Set Doc = ActiveDocument
        Doc.Save
        Doc.Content.Copy
        With EmailItem
            .Subject = "Insert Subject Here"
            .BodyFormat = olFormatRichText
            Set oEditor = .GetInspector.WordEditor
            oEditor.Content.Paste
            .To = "user@example.com"
            .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
            .Display 'Send
        End With
        Application.ScreenUpdating = True
        Set Doc = Nothing
        Set OL = Nothing
        Set EmailItem = Nothing
    End Sub

  4. #4
    Banned VBAX Newbie
    Joined
    Jul 2022
    Posts
    5
    Location
    Trying to integrate document contents directly into Outlook emails can be a bit tricky. From what I've tinkered with, modifying the code to transfer document contents to the email body instead of attaching as a PDF involves adjusting how the Doc.Content.Copy is handled.

  5. #5
    Banned VBAX Newbie
    Joined
    Jul 2022
    Posts
    5
    Location
    Quote Originally Posted by inkaterу View Post
    Trying to integrate document contents directly into Outlook emails can be a bit tricky. From what I've tinkered with, modifying the code to transfer document contents to the email body instead of attaching as a PDF involves adjusting how the Doc.Content.Copy is handled.
    You might need to experiment with pasting the content directly into .Body instead of using .Attachments.Add.
    Last edited by Aussiebear; 07-10-2024 at 11:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •