Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 9th, 2005, 04:59 AM
Registered User
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to saimen
Default Send Mail from Word with formatted Body


Maybe this is a little bit off-topic because it's about Word & VBA and not Excel & VBA but I found that it fits best in this category...

I'm having a word document which can be sent to Outlook automatically. This is done by creating a new Outlook message (specified: outlook invitation) and then attaching the (temporary saved) doc-file as attachment to the message. It's all done with vba and looks like this:
Private Sub einladungErstellen()
    Dim objOL   'As Outlook.Application
    Dim objAppt 'As Outlook.AppointmentItem
    Dim attPath As String
    Const olAppointmentItem = 1
    Const olMeeting = 1

    attPath = Tempfile
    Set objOL = CreateObject("Outlook.Application")
    Set objAppt = objOL.CreateItem(olAppointmentItem)
    With objAppt
        .Subject = Title
        .Start = Startdate
        .End = Enddate
        .Location = RoomName
        .MeetingStatus = olMeeting ' make it a meeting request
        .Attachments.Add attPath
        .Body = "This is a test-text in the message body..."
    End With

    Set objAppt = Nothing
    Set objOL = Nothing
    Kill Tempdatei
End Sub
When I run the code, everything is working well and without any problems. But I would like to paste the formatted content of the word file directly to the message body. At the moment, I only know how to send unformatted text to the message body:
objAppt.Body = "This is my text"
How can I send formatted text as body content?

=> Maybe one could do this with a complete different approach: It's possible to copy the worddocument-content to clipboard and then paste it manually in the generated outlook message with 'ctrl+v'. Would it be possible to automate this?

thank you,

Old February 10th, 2005, 07:53 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts


Have a look at this link.


The solution involves asving your word document as an HTML file and the subsequently setting the HTMLbody property of the appiontment item to be equal to the html code of the saved word file.

The solution you were alluding to would be to use the SendKeys method in VBA (have a look in Help for more info). Whilst it would work it is to be avoided if possible due to the sorts of errors that can crop up.


Similar Threads
Thread Thread Starter Forum Replies Last Post
text file in the body of e-mail mlov83 Word VBA 1 May 1st, 2008 09:18 AM
HTML formatted mail goes to BadMail. Why? nancy Classic ASP Basics 12 August 24th, 2004 10:19 AM
Sending a CSS formatted HTML mail madhukp Classic ASP Basics 4 June 17th, 2004 11:30 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.