How to insert MS Word formatted content into Outlook mail?












0















The Problem



This code sends mail with MS Word.



The mail body is same as the Word content but the mail body is unformatted.



How is it possible to insert the formatted Word document content into the mail body?



Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub









share|improve this question

























  • Maybe the body is set to plain text? MailItem.BodyFormat Property

    – Dávid Laczkó
    Nov 17 '18 at 14:01













  • The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

    – dotvihar
    Nov 19 '18 at 10:12













  • Possible duplicate of this, the accepted answer lists possibilites.

    – Dávid Laczkó
    Nov 19 '18 at 11:03











  • You may make an answer post and accept as well. stackoverflow.com/help/self-answer

    – niton
    Nov 19 '18 at 21:30











  • @niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

    – dotvihar
    Nov 20 '18 at 6:49


















0















The Problem



This code sends mail with MS Word.



The mail body is same as the Word content but the mail body is unformatted.



How is it possible to insert the formatted Word document content into the mail body?



Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub









share|improve this question

























  • Maybe the body is set to plain text? MailItem.BodyFormat Property

    – Dávid Laczkó
    Nov 17 '18 at 14:01













  • The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

    – dotvihar
    Nov 19 '18 at 10:12













  • Possible duplicate of this, the accepted answer lists possibilites.

    – Dávid Laczkó
    Nov 19 '18 at 11:03











  • You may make an answer post and accept as well. stackoverflow.com/help/self-answer

    – niton
    Nov 19 '18 at 21:30











  • @niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

    – dotvihar
    Nov 20 '18 at 6:49
















0












0








0


1






The Problem



This code sends mail with MS Word.



The mail body is same as the Word content but the mail body is unformatted.



How is it possible to insert the formatted Word document content into the mail body?



Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub









share|improve this question
















The Problem



This code sends mail with MS Word.



The mail body is same as the Word content but the mail body is unformatted.



How is it possible to insert the formatted Word document content into the mail body?



Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub






vba outlook ms-word






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 6:47







dotvihar

















asked Nov 16 '18 at 8:35









dotvihardotvihar

138




138













  • Maybe the body is set to plain text? MailItem.BodyFormat Property

    – Dávid Laczkó
    Nov 17 '18 at 14:01













  • The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

    – dotvihar
    Nov 19 '18 at 10:12













  • Possible duplicate of this, the accepted answer lists possibilites.

    – Dávid Laczkó
    Nov 19 '18 at 11:03











  • You may make an answer post and accept as well. stackoverflow.com/help/self-answer

    – niton
    Nov 19 '18 at 21:30











  • @niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

    – dotvihar
    Nov 20 '18 at 6:49





















  • Maybe the body is set to plain text? MailItem.BodyFormat Property

    – Dávid Laczkó
    Nov 17 '18 at 14:01













  • The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

    – dotvihar
    Nov 19 '18 at 10:12













  • Possible duplicate of this, the accepted answer lists possibilites.

    – Dávid Laczkó
    Nov 19 '18 at 11:03











  • You may make an answer post and accept as well. stackoverflow.com/help/self-answer

    – niton
    Nov 19 '18 at 21:30











  • @niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

    – dotvihar
    Nov 20 '18 at 6:49



















Maybe the body is set to plain text? MailItem.BodyFormat Property

– Dávid Laczkó
Nov 17 '18 at 14:01







Maybe the body is set to plain text? MailItem.BodyFormat Property

– Dávid Laczkó
Nov 17 '18 at 14:01















The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

– dotvihar
Nov 19 '18 at 10:12







The mail is in HTML format already but it lost formatting when come from Word to Outlook mail.

– dotvihar
Nov 19 '18 at 10:12















Possible duplicate of this, the accepted answer lists possibilites.

– Dávid Laczkó
Nov 19 '18 at 11:03





Possible duplicate of this, the accepted answer lists possibilites.

– Dávid Laczkó
Nov 19 '18 at 11:03













You may make an answer post and accept as well. stackoverflow.com/help/self-answer

– niton
Nov 19 '18 at 21:30





You may make an answer post and accept as well. stackoverflow.com/help/self-answer

– niton
Nov 19 '18 at 21:30













@niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

– dotvihar
Nov 20 '18 at 6:49







@niton Thank you for calling my attention. When I asked, I did not know the answer yet. Later I found the solution based on the information received.

– dotvihar
Nov 20 '18 at 6:49














1 Answer
1






active

oldest

votes


















1














The solution



(Edited on 2018.11.19)



After some hours I found the solution:



Sub SendMail()

Selection.WholeStory
Selection.Copy

Dim olapp As Object
Dim olemail As Object
Dim olInsp As Object
Dim wddoc As Object

On Error Resume Next
Set olapp = GetObject(, "Outlook.Application")
If Err <> 0 Then Set olapp = CreateObject("Outlook.Application")
On Error GoTo 0
Set olemail = olapp.CreateItem(0)
With olemail
.BodyFormat = 3
.To = "example@example.com"
.Subject = "Test mail"
Set olInsp = .GetInspector
Set wddoc = olInsp.wordeditor
wddoc.Content.Paste
.Display
End With
End Sub





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334107%2fhow-to-insert-ms-word-formatted-content-into-outlook-mail%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The solution



    (Edited on 2018.11.19)



    After some hours I found the solution:



    Sub SendMail()

    Selection.WholeStory
    Selection.Copy

    Dim olapp As Object
    Dim olemail As Object
    Dim olInsp As Object
    Dim wddoc As Object

    On Error Resume Next
    Set olapp = GetObject(, "Outlook.Application")
    If Err <> 0 Then Set olapp = CreateObject("Outlook.Application")
    On Error GoTo 0
    Set olemail = olapp.CreateItem(0)
    With olemail
    .BodyFormat = 3
    .To = "example@example.com"
    .Subject = "Test mail"
    Set olInsp = .GetInspector
    Set wddoc = olInsp.wordeditor
    wddoc.Content.Paste
    .Display
    End With
    End Sub





    share|improve this answer




























      1














      The solution



      (Edited on 2018.11.19)



      After some hours I found the solution:



      Sub SendMail()

      Selection.WholeStory
      Selection.Copy

      Dim olapp As Object
      Dim olemail As Object
      Dim olInsp As Object
      Dim wddoc As Object

      On Error Resume Next
      Set olapp = GetObject(, "Outlook.Application")
      If Err <> 0 Then Set olapp = CreateObject("Outlook.Application")
      On Error GoTo 0
      Set olemail = olapp.CreateItem(0)
      With olemail
      .BodyFormat = 3
      .To = "example@example.com"
      .Subject = "Test mail"
      Set olInsp = .GetInspector
      Set wddoc = olInsp.wordeditor
      wddoc.Content.Paste
      .Display
      End With
      End Sub





      share|improve this answer


























        1












        1








        1







        The solution



        (Edited on 2018.11.19)



        After some hours I found the solution:



        Sub SendMail()

        Selection.WholeStory
        Selection.Copy

        Dim olapp As Object
        Dim olemail As Object
        Dim olInsp As Object
        Dim wddoc As Object

        On Error Resume Next
        Set olapp = GetObject(, "Outlook.Application")
        If Err <> 0 Then Set olapp = CreateObject("Outlook.Application")
        On Error GoTo 0
        Set olemail = olapp.CreateItem(0)
        With olemail
        .BodyFormat = 3
        .To = "example@example.com"
        .Subject = "Test mail"
        Set olInsp = .GetInspector
        Set wddoc = olInsp.wordeditor
        wddoc.Content.Paste
        .Display
        End With
        End Sub





        share|improve this answer













        The solution



        (Edited on 2018.11.19)



        After some hours I found the solution:



        Sub SendMail()

        Selection.WholeStory
        Selection.Copy

        Dim olapp As Object
        Dim olemail As Object
        Dim olInsp As Object
        Dim wddoc As Object

        On Error Resume Next
        Set olapp = GetObject(, "Outlook.Application")
        If Err <> 0 Then Set olapp = CreateObject("Outlook.Application")
        On Error GoTo 0
        Set olemail = olapp.CreateItem(0)
        With olemail
        .BodyFormat = 3
        .To = "example@example.com"
        .Subject = "Test mail"
        Set olInsp = .GetInspector
        Set wddoc = olInsp.wordeditor
        wddoc.Content.Paste
        .Display
        End With
        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 6:47









        dotvihardotvihar

        138




        138
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334107%2fhow-to-insert-ms-word-formatted-content-into-outlook-mail%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine