Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Email Excel As Html Body

Hi, I have a excel file with data and an image inside. I would like to email the excel file as the email body via outlook (Not as attachment!) by clicking a button. I found some sample codes in the forum about how to send email but all of them are using attachment method. Can anyone provide some sample code? thanks!

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Sending HTML In EMail Body
I am trying to send html formatted text in my app and I am using the winsock control. I got this code below working fine, but i cannot get it to display the html only plain text. Can anyone help?

With ctlSMTP1
' set mail server
.MailHost = ""
.MailPort = 25

' set message properties
.Subject = "Test mail from SMTP control"
.ToPerson = "My name"
.FromAddress = "" ' not a real address
.FromPerson = "Name <>"

' add addresses
.AddAddress ""

' set body
.BodyData = "<font color=green>Welcome to my email</font>" & _
vbCrLf & vbCrLf & "<h1>It is working...</h1>"

' send
End With

How Can I Find Out If The Email Body Is In Html Format?
i'm using msoutlook to manipulate the emails.
I want to know the way to find out that the body of the email message is written by html..
I see that outlook can tell whether the body of the message is html or plain text,. but how can i tell it programmatically?

thank you

Attaching A Html Document To The Body Of An Email
I am using MAPI sessions to create an interface for sending internet faxes using vb6.

Using vb6 I have created an html page. how do I attach the html page to the body of the email after it has been created without physically selecting it?

this html page is my fax cover letter

Enclosing A Html File In The Email Body
Hi there,

I have a report in html format that need to be sent out as the body (not attachement) of the email using outlook.

In order to accomplish that I think I will have to read the html report into a string var then assign the string to htmlBody.

I am wondering if there is any simpler way to do it something like:

                                 htmlBody = myReport.html     (of course this won't work)

Thanks in advanced!


Email HTML Document In Body From Access 97 Button Click

Working in Access 97.

I have a standard HTML document.

From a click on a form I need to open an email, insert the email address on the form AND (here is the problem)...Insert the HTML code from the document into the body of the email. No attachment....

Anyone have any ideas?

Attaching HTML File To Email Puts Data In Body
I've spent nearly 3 hours trying to figure this out with a heavy cold and it's driving me nuts!

I have some code to generate (but not send) an Outlook Email.
CODEPublic Sub InitiateOutlookEmail(ByVal strToAddress As String,
                                ByVal strCCAddress As String,
                                ByVal strSubject As String,
                                ByVal strBody As String,
                                ByVal strFileAttachment As String)
   Dim appOutlook       As Object
   Dim objMailItem      As Object
   Dim blnExisting      As Boolean
   Const cPROC          As String = "InitiateOutlookEmail"
   Const olMailItem     As Long = 0
   blnExisting = True
   'get reference to any currently open Outlook session
   Set appOutlook = GetObject(, "Outlook.Application")
   If Not blnExisting Then Set appOutlook = CreateObject("Outlook.Application")
   Set objMailItem = appOutlook.CreateItem(olMailItem)
   With objMailItem
      'message subject
      .Subject = strSubject
      If LenB(Trim$(strBody)) > 0 Then .Body = strBody
      .To = strToAddress
      'CC Address required?
      If LenB(Trim$(strCCAddress)) > 0 Then .CC = strCCAddress
      'check if attachment required and attach
      If LenB(Trim$(strFileAttachment)) > 0 Then .Attachments.Add (Trim$(strFileAttachment))
   End With

   'de-reference objects
   Set objMailItem = Nothing
   Set appOutlook = Nothing

End Sub

Attaching Excel Into The Body Of The Email..
I want to send an email(outlook object) from VB code.
In the body of that email, I would like to have an Excel work sheet. NOt as an attachement. but the body itself should have the excel file.

how can I do that programmatically do that?

Sub SendEmail()

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.subject = "This is the Subject line"
.HTMLBody = SheetToHTML(ActiveSheet)
.body = Sheets("DOD Action Plan Email")


End With
Application.ScreenUpdating = True
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Help is greatly appreciated.


Different Ways To Email Notes Body In Excel
Hi All,

My previous thread got moved although I think this is an Excel issue.

The code, set off with a commandbutton pops up 4 textboxes....
First one for the recipient, second for the subject.

Now, the third and fourth pop up, are textboxes that will complete a range in the workbook. I want to copy - paste this range in the body of the Email.

Isn't this possible with Lotus Notes....? Everything works in the code, just the body isn't there....

Please help!

Private Sub CommandButton1_Click()
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim vaRecipient As Variant 'Array of recipients
Dim vaSubject As Variant 'ze subjekt
Dim vaBodyCMR1 As Variant 'Bodyrange1
Dim vaBodyCMR2 As Variant 'Bodyrange2
Dim i As Long 'Counter

vaRecipient = Application.InputBox( _
Prompt:="Please enter the recipient mailaddress:" & _
vbCrLf & "(", _
Title:="Recipient", _
Loop While vaRecipient = ""

If vaRecipient = False Then Exit Sub

vaSubject = Application.InputBox( _
Prompt:="Please enter the subject:" & _
vbCrLf & "(Regarding MSO nmber 00001)", _
Title:="Recipient", _
Loop While vaSubject = ""

If vaSubject = False Then Exit Sub

vaBodyCMR1 = Application.InputBox( _
Prompt:="Please type the name/title" & _
vbCrLf & "(Sir or Michel)", _
Title:="Recipient", _
Loop While vaBodyCMR1 = ""

If vaBodyCMR1 = False Then Exit Sub

vaBodyCMR2 = Application.InputBox( _
Prompt:="Please enter the CMR FROM TO Destination:" & _
vbCrLf & "(From Pon Denmark to Finning UK)", _
Title:="Recipient", _
Loop While vaBodyCMR2 = ""

If vaBodyCMR2 = False Then Exit Sub

Range("aa1") = vaBodyCMR1
Range("aa5") = vaBodyCMR2

'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")

'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "mailusername.nsf")
If Maildb.IsOpen = False Then
End If

'Set up the new mail document
MailDoc.Form = "Memo"
MailDoc.sendto = vaRecipient
MailDoc.Subject = vaSubject
MailDoc.Body = Worksheets("Infosheet").Range("aa1:aa14")

'This is supposed to be the property, but works
'on some systems only
'without an apparent reason of failure

'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
End If

'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0
MailDoc.Save True, True, False

End Sub


Send Excel Worksheets In Body Of Email To Different Recipients
I'm what you could call a very entry-level vb user...I'm trying to set up a macro in excel to send each worksheet within one workbook, in the body of an email, to different email addresses. I found I can do manually going to File, Send to, Mail Recipient..., but can't figure out how to please?

Add Senders Email In Body Of Email - Emailing With Shellexecute
I am loking for a little help. I would like to include the senders email address in an email's body which I generate using shellexecute but after much looking can not find if or where I can get this string from? Any ideas would be much appreciated.

I am using:

strcommand = " your subject here&body=message here including senders email address."
Call ShellExecute(0&, vbNullString, strCommand, vbNullString, vbNullString, 5)

Email Body
On my form I have 2 Labels and 4 textboxes, I need to add the contents of the labels (Caption) and the text in the textboxes into my email body when I click a button.

Here's my code so far:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, ";", vbNull, vbNull, SW_SHOWNORMAL

End Sub

What code do I put after &body= or do I have the wrong code all together?

I'm running VB5

Email Body
ShellExecute 0, "Open", ""

this will open outlook with e-mail
and subject Hello

how can I also set the body in outlook to a string i choose ?


RTB And Email (&amp;body)
If I put this in my code:

MailBody = RTB1.Text

and send it to the body of Outlook-Express then there are not CR, how come ??

ShellExecute hwnd, "open", "" & _
"?subject=" & MailSubject$ & "&Body=" & MailBody _
, vbNullString, vbNullString, SW_SHOW

Output To The Body Of An Email.
Hi All,

I know this has probably been asked here somewhere already, but I can't find it, and maybe you guys can help me out.

I've wrote an estimating program that realy kicks butt. Save me many hours of repeted calculations. You just put in the specs and boom, it kicks out the results to the screen or to the printer. Now I'm trying to get it dump this same info to the "body" of an email. I've got the MAPI to load and open a new email (outlook express), but for the life of me I can't get the output to flow into the body of the email. Can you guys help me out?


Pictures In Email Body
I have written a program whereby users can write nice messages in a richtextbox. It also allows for the adding of pictures, and this is where the problem comes in:

After creating their message a user is able to email it. I'm using MAPI to email it, but I don't want the message to become an attachment. It would be great if the entire message, picture and all, becomes part of the emails body (pictures are read from a server, don't worry, I believe in thin client )

I spent all weekend reading up, thinking, fretting, you name it. How do I programmatically insert text and pictures from a richtextbox into an email body, desperation is calling

Using A File For Email Body
I have been asked to put together a little script (I've never really programmed before) in LotusScript. It has to create an email where the body is composed from an existing HTML file. I can create the email fine, using the create object("Outlook.Application") and attach the file no problems.
However I have no idea how to get the body of the file into the body of the email
Any help would be greatly appreciated.

Attaching Body To Email
I have an email program that opens the default email browser inserts the email subject and body. My only problem is that the body needs to be a range of cells is there a way to do this?
Here is the code

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Sub Choice1_Click()
Dim s As String
Dim hWndX As Long
hWndX = FindWindow("XLMAIN", Application.Caption)

s = ""
s = s & "?Subject=test of attachments"
s = s & "&Body=body goes here"
ShellExecute hWndX, "open", s, vbNullString, vbNullString, SW_SHOWNORMAL
End Sub

Know someone that owns a child care business. Go to It will help them greatly

.sendmail And Body Of Email
Is there any way to specify the BODY of the email message via EXCEL API?

oxlApp.Application.ActiveWorkbook.sendMail(recipient, subject)

Print Email Body Only?
is there a way to do this with a macro, or some plugin perhaps I could make in VB6?
I have seen buttons added to various other applications (word comes to mind) that have special buttons added from some third party app to preform a special function. I would like to have an online form that gets data from textboxes, creates a plain, completed form in email and sends it to through our smtp box (which I can do both of these things already)

but on certain end users, I would like to have an option to only print the body (aka the form part) and dont worry about headers and footers and all that. just the stuff in the body.

I know web and vb well enough to code something but i know nothing of integration with other apps. anyone have any ideas?

Body Text In An Email
I am using the following code to paste an Excel worksheet from a workbook into an email (Groupwise NOT Outlook!) as an attachment using the following simple code:

WB.SendMail "", "Email title"

The problem I am having is I can't get the macro to write any body text.

Can anyone help?

RichTextBox To Email Body
I have formatted text in a RTB. (colored, sized and fonts), how can I send it as the body of an email (not as an attachment). I'm sending it to Outlook, I tried .

oOutlook.HTMLBody = txtBody.TextRTF '// this method is in one continous line, unless I include html tags
oOutlook.Body = txtBody.Text '//This is formatted but no color or size

If I use html tags and the user selects an .rtf file to embed in the RTB that would be a hell of lot of parsing.

Formatting Body Of An Email
Can someone help me with formatting the body of an email message? I'm doing okay except that I need everything to appear on separate lines. The only thing in the body of the message is all the contents of a list box. Here's what I've got...

For i = 0 To List1.ListCount - 1
List1.ListIndex = i
strBody = strBody & vbCrLf & List1.Text & vbCrLf
Next i

strMailTo = "mailto:&subject=Subject&body=" & strBody
lngResult = ShellExecute(Me.hwnd, "Open", strMailTo, "", "", vbNormalFocus)

The problem is that it is going into the body of the email like this:

Line 1 Line 2 Line 3

when I need it to go like this

Line 1
Line 2
Line 3

Any help appreciated. Thanks in advance.

Shellexecute Email And Body
i know that this will open outlook and put the email address in and put hello in the message box.
how do you get the text from a textbox in the body.

ShellExecute Me.hwnd, vbNullString, "mailto:someones email@somewhere?body=Hello", vbNullString, "C:", SW_SHOWNORMAL

thank you

RichText Vb In Body Email
I would want to insert in body of an email sended via smtp the content of one richText Box of visual basic with richtext1.textRTF. it is possible to make this?

There is mime for rich text?

Email Body Length
Can someone help me out abit ....I'm using the code below for email,But after the body reaches about 500 space,letters,and or numbers it will not send.......can someone tell me what part of the code for the body do I change to add more room.....I'd like to double or triple it......

Public Function SendMail(lhWnd As Long, Optional Address As String, _
Optional Subject As String, Optional Body As String, _
Optional CC As String, Optional bcc As String, Optional Attachement As String)

Dim strCommand As String

'bygger opp "mail-strengen"
If Len(Subject) Then strCommand = "&Subject=" & Subject
If Len(Body) Then
Body = Replace(Body, "&", "%26")
Body = Replace(Body, " ", "%20")
Body = Replace(Body, vbCrLf, "%0D%0A")
Body = Replace(Body, vbCr, "%0D")
Body = Replace(Body, vbLf, "%0A")
strCommand = strCommand & "&Body=" & Body & "%0D%0A"
End If

If Len(CC) Then strCommand = strCommand & "&CC=" & CC
If Len(bcc) Then strCommand = strCommand & "&BCC=" & bcc
If Len(Attachement) Then strCommand = strCommand & "&Attacth=" & Chr(34) & Attachement & Chr(34)

'passer på at første tegn er et ?-tegn
If Len(strCommand) Then
Mid(strCommand, 1, 1) = "?"
End If

'legger til teksten "mailto:" og hoved adresse
strCommand = "mailto:" & Address & strCommand

'Starter default mail program v.h.a shellexecute
Call ShellExecute(lhWnd, "open", strCommand, _
vbNullString, vbNullString, SW_SHOWNORMAL)

End Function

Email Body Text - Help!
Ok, firstly thanks to everyone who looks at this thread and posts, as I'm finding solving my current problem not only tricky, but extremely irritating.

Basically, I am tweaking the website for the company where I work and am trying to grab information from a form which potential customers fill out, then email those fields to our email address.

The form has been written, and works fine. I've also written the script to grab the info and email it, which runs fine... problem lies with tweaking the body text to include headers which will help those who receive the emails ascertain to which field the information that has been mailed is taken (currently the form information is simply listed in the email, with a line break between each section. So, for example, the first line shows whatever the customer filled out in the 'Name' field on the form, but nothing to indicate to the email reader that that is the name field).

Incidentally, please disregard the strange field names. They are all correct, and do work, they are just thus named due to me being lazy and simply copy/pasting new fields in, rather than naming each one.

My script, which grabs from the form, is as follows. This script works perfectly, I just don't know how to add indications into the body text as to which bit of information belongs to which field.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


Set Mail = Server.CreateObject("SMTPsvg.Mailer") 'create an Asp mail component.
Mail.FromName = Request.Form ("email")
Mail.FromAddress = Request.Form ("email3")
Mail.RemoteHost = "" ' The mail server you have to use with Asp Mail
Mail.AddRecipient "US", ""
Mail.Subject = "Customer Request"
Mail.BodyText = Request.Form("email") & vbcrlf & Request.Form("email2") & vbcrlf & Request.Form("email4") & vbcrlf & Request.Form("email5") & vbcrlf & Request.Form("email6") & vbcrlf & Request.Form("email7") & vbcrlf & Request.Form("email72") & vbcrlf & Request.Form("email73") & vbcrlf & Request.Form("email732") & vbcrlf & Request.Form("email7322") & vbcrlf & Request.Form("email733") & vbcrlf & Request.Form("info")
if Mail.SendMail then
Response.Write "Mail send failure. Error was " & Mail.Response
end if
Set Mail = Nothing



How Do I Send A URL In The Body Of An Email?
Hi, I am super new to this and I cannot find info on this in my searchs. Here is what I want to do..

I am creating an Outlook mail message object. I can set the recipient, subject, and body as text, but what I want to do is to send a hyperlink/url in the body of the messge.

Any Ideas?

Here is my code:

    Dim Body As String
    Dim myOlApp As Object
    Set myOlApp = CreateObject("Outlook.Application")

    Body = "This is a neat URL: Http://"
    Set emailMsg = myOlApp.CreateItem(0)
    emailMsg.Subject = "Neat URL"
    emailMsg.Body = Body
    emailMsg.Recipients.Add ""

Maybe I should declare it differently? I do not know.... Any hlpe is greatly appreciated!


HTML Body In Outlook

I'm try to cut and paste a range of cells from excel to outlook as a HTML body.

I don't know where to start and any help would be greatly appreciated


OlMail.HTML Body
I'm using the following code to output text to my outlook mail body.

It works in that it changes the colour text and sets the text to bold, BUT it doesnt recognise the VbCrlf lines.

I need the program to leave a carriage return between my "MSG" and text = "NEw invoice numbers" ----- reason ---to make my mail more readable.

Anyone know why olMail.HTMLbody doesnt recognise vbCrlf??
I'd appreciate your help greatly.

VB Code:
olMail.HTMLBody = msg & vbCrLf & vbCrLf & "<htmlbody><font color=#0000FF><b>New Invoice Numbers:</b></font>" & myvar & vbCrLf & vbCrLf & "</htmlbody>"

Send Email: Contactitem.body HELP!
Outlook 2000, VB 6.

Want to add functionality:

Contact and/or Journal item, send [Notes] field as email to hardcoded address(s) by

1. select text, then with control button, send

and / or

2. Using control button, send all [Notes]

How to do it?

Thank you.

Send Email, As Body, With Chart?
Edit by Moderator:

There wouldn't happen to be any new ideas or developments on this problem, would there? I'm hoping to do the same as above.

Original thread is over 1 month old and therefore archive-only. Please create your own thread in future.

Thank you.

Email With Doc Directly In Body, Not As An Attachment
Hi everyone,
Just need to automate (working in Access) an email where the body will be something from word / excel, NOT as an attachment but directly in the body.

I tried already with DoCmd.SendObject, but the body is just a string to be written in the code:
DoCmd.SendObject , , , test@com, , , "Subject", "body is a string", False

I tried also with .body, but same problem.

Using SendKeys to paste what I copied before does not work apparently.

Any ideas are more than welcome. Thanks

Need Help Body Back Ground In Email
Hi Friends

I have a program which sends mails to the customers... I want to put a body background..

But I could view the body back ground others could not.. can any one help.. the code is follows..

Also if i give instead of body background as <img src> only i could view.

Dim objOutlook As Object
Dim objOutlookMsg As Object
dim body1 as string

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = ""
.Subject = "Hello..."

body1 = "<html><p><b><font size=5> Dear Customer </font><b></p><p>&nbsp;</p><center><table width= 285><tr><font color=#cbfea5 size=4 align= center> </font><br><br><font color= #f80000 size=5> Have a Nice Day </font></tr></table></center><body background=cust.jpg></body></html>"
.HTMLBody = body1
'.Attachments.Add ("c:emailcuso.jpg")
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing

Email With Mapi: Body Message
I had writen a function to send an email from Vb using MAPI functions. The code is shown below:

With MAPIMessages1
.SessionID = MAPISession1.SessionID
.MsgIndex = -1
.RecipDisplayName = ccC
.MsgSubject = cS
.MsgNoteText = ""
.AttachmentName = Right(cDestino, 16)
.AttachmentPathName = cDestino
End With

My default email app is Incredimail.
It works fine, but always I get the same unexpected information in the body message:
Content-Type: Text/Plain


What's wrong? How I can supress that message?


Sending Email With Vb - Attachments Become Body?
I am using vb to send out emails automatically with outlook 97 and exchange server 5.5. Internally everything works great, but when emails go externally the attachment (text file) becomes part of the body of the text. I believe this code was working at one time, but stopped working a few weeks ago. Does anyone know of any patches for outlook or exchange that would cause this or if i can change my code to fix the problem? The email and my source are shown below - If anyone can help me, it would greatly be appreciated.


Sub SendEmail(attachfile, txtEmailList, txtReportName)
Dim o
Dim m
Set o = CreateObject("Outlook.Application")
Set m = o.CreateItem(0)
m.To = txtEmailList
m.Subject = txtReportName
m.Body = " "
m.Attachments.Add attachfile
'Repeat this line if there are more Attachments
'm.Send 'If you want to just send it

End Sub

Email example:

Date: Thu, 24 Apr 2003 08:15:21 -0400
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: multipart/mixed;

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

Content-Type: text/plain

Content-Type: text/plain;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;

Application~SSN~Emp Name~Term Beg~Term End~Amount~Check~Receipt =
Proof~Grades Proof~Pay to Name =

L~01/06/2003~05/05/2003~1326~32843~01/07/2003~~Grand Valley State =
1282~xxx~RACHEL, REEDER R~03/13/2003~04/17/2003~1257~35089~~~*** =
Invalid Award Vendor 100571



This E-mail message and any attachments may contain
legally privileged, confidential or proprietary
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of
this message to the intended recipient(s), you are
hereby notified that any dissemination, distribution
or copying of this E-mail message is strictly
prohibited. If you have received this message in
error, please immediately notify the sender and
delete this E-mail message from your computer.

Autofilling Out Body Of An Email In Outlook
Hello peeps....

My prog creates default emails at the moment with senders email and Subject lines ready populated. Is it possible (or easy) to automatically fill the body aswell and send it automatically?

Thank you oh Gods of enlightenment and beer breath.

Problem Getting Link In Body Of Email
In my asp page I am sending a an email and need to have a link in the body. The problem is that it is not showing up as a link in the email. I have tried using chr(34) as well but that doesn't work either. Any suggestions?

VB Code:
mymail.Body="At your request, the following new password has been created for the TrafficBoss Client Center:  <B>" & pass &"</B> . <BR><BR>Please use the following link to login and change your temporary password: <a href """">TrafficBoss Client Center</a>"

Can Email Body Be Formatted Using A Macro?
Hey All,

Do not do any VBA programming but have been asked to write a macro to allow users to auto-format their email body. I wrote this so far but had some questions I'm hoping you can answer. Is it best to do it the way I have and assign the formatted text to a string or should I be using the PRINT # method? Also, I wanted to test below and in Excel, using a macro you can assign the code execution to a keyboard key like 'G8' that automatically runs your code. I can not find this same functionality and think I am missing something. Writing a macro for Outlook is not the same as writing one for Excel? :

Private Sub NonConformanceTemplate()
    Dim myMail As Outlook.MailItem
    Dim strBodyFormat As String
    Set myMail = Application.CreateItem(olMailItem)
    myMail.Subject = "Non-Conformances"
    strBodyFormat = Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    "SOP 1.2/F7" & Chr(13) & _
                    " NON-CONFORMANCES " & Chr(13) & _
                    Chr(13) & _
                    "1.DESCRIPTION OF SITUATION/PROBLEM " & Chr(13) & _
                    "(include date of incident or date situation noticed):" & Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    "2.NOTIFIED SUPERVISOR: Y N " & _
                    " NAME:_______________________" & _
                    " DATE:_______________________" & _
                    Chr(13) & _
                    Chr(13) & _
                    "3.CORRECTIVE ACTION TAKEN: " & _
                    Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    Chr(13) & _
                    "Testing" & Chr(13) & _
                    "Continue under current conditions: "
    myMail.Body = strBodyFormat
End Sub

Help Sending Email With Rtf Contents As Body In Vb

I am trying to send a document using and outlook and words, The type of file i would like to send are (rtf, doc, txt) as the message body in the outlook message. Any one with experince in this area the help will be surely appreciated.

I have added the code below i get some type of hresult type error when i run this.

Public Sub SendDocMsg(ByVal subjectp As String, ByVal pEmail As String, _
    ByVal fileDirLocation As String)

        recipient = pEmail
        subject = subjectp

        Dim oLApp As Object
        Dim oItem As Object
        Dim oDoc As Object

        On Error GoTo errorHandler

        'Create a new mailitem
        ' oOutlook = New Outlook.Application
        oLApp = CreateObject("Outlook.Application")
        oItem = oLApp.CreateItem(0)
        oDoc = CreateObject("Word.Application")
        oDoc.Visible = True

        With oItem

            'Set the recipient for the new email
            .To = mRecipient

            'Set the recipient for a copy
            '.CC = ""

            'Set the subject
            .Subject = mSubject

            'The content of the document is used as the body for the email
            .Body = oDoc.ActiveDocument.Content

        End With

        MsgBox(Err.Number & " " & Err.Description)
        'Clean up
        oItem = Nothing
        oLApp = Nothing
        oDoc = Nothing

    End Sub ' SendMsg

Send An HTML Document As The Body
Hi, I'm sure this question has been asked in the past. I have a HTML document that I would like to send as the body of an Outlook email. I'm using VB 6 and Outlook 2000. I am currently sending this as an attachment, so I have the appropriate code for that.

Thanks, Carl

Search Within The Html Body Of A File?
I have a folder of knowledge base items, all in HTML and placed in sub folders by category. I am trying to get code which will open each folder and then each file within the folder to search for a given string. basically I want a simple form which requests a search string and has a list box with the resulting names of the files that contain the given search string.
I have managed to get some way toward this with VBS, but I want to do this in VB6. Listing the files and sub-files is no 'biggie' but putting that with the text search has me lost.
can anyone point me in the right direction - how do i search within the html body of a file and return the name of the file if the search is true?


Get Html Body From Outlook Into Word
I have an application that sends users confirmation of a web order that they ahve recieved on thier website. One of my clients have been very successfull with this app and recieve as many as 400 web orders per day. The problem is that when you print more than 30 HTML e-mails the printer has a problem with the outbind://##### thing and it causes the printer to hang.

My solution was to write the code below to try to print all the e-mails in one print job by using word to compile them

Problem is the word document just shows the code. I can't get word to allow a pastespecial using HTML

Public Function PrintNewMOs()
Dim output As String

Dim i, j, k, l As Integer
Set colApp = CreateObject("Outlook.Application")
Set colNameSpace = colApp.GetNamespace("MAPI")
Set colFolders = colNameSpace.GetDefaultFolder(olFolderInbox)
Set wdapp = CreateObject("Word.Application")
Dim oDoc As Word.Document


'set counters
i = 1
j = 1
k = 1
l = 1
For Each myFolder In colNameSpace.Folders 'Parent nodes
For Each mySubFolder In myFolder.Folders 'Folder Child nodes
If mySubFolder.Name = "Inbox" Then 'subfolders in inbox
For Each mySubSubFolder In mySubFolder.Folders
k = k + 1
If mySubSubFolder = Form1.cmbFolder1.Text Then
If mySubSubFolder.Items.Count > 0 Then
For Each myItem In mySubSubFolder.Items
l = l + 1
Clipboard.SetText (myItem.HTMLBody)
wdapp.Selection.PasteSpecial DataType:=wdPasteHTML
wdapp.Selection.InsertBreak Type:=wdPageBreak

'lblBody.Caption = l - 1 & " messages processed. Press the 'View Database' button to view your records."
'l = 1
'Do While mySubSubFolder.Items.Count > 0
' For Each myItem In mySubSubFolder.Items
' myItem.Delete
' l = l + 1
' Next
MsgBox "No messages remain in the " & cmbFolders.Text & "folder."
lblBody.Caption = "Press the 'Open Access Database' button to view your records."
End If
End If
l = 1
End If
k = 1
j = j + 1
j = 1
i = i + 1

wdapp.Visible = True

End Function

Microsoft Outlook - HTML Body
Dear all,

We can use text box in VB to type and pass value to
recipient (txtEMail) and subject (txtSubject).

What control should we use if we want to paste a picture
in the HTMLBody from Clipboard (not as an attachment, but
embedded in the Message Body itself)?

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.Subject = txtSubject.Text
objMail.HTMLBody = txtBody.Text

Thanks in advance

HTML Edit Control, Any Body Knows?
Anybody knows of some control that will allow saving the formatted Text in HTML, like the RichTextBox does in RTF?
Or any code example that will convert rtf into html?

How To Read The Body Of HTML Using WinInet
Hi, I want to use the WinInet to read the body of HTML , I read somewhere that InternetRead function could be used but it is not retrieving the contents of HTML body. Read the microsoft aricle at

Please someone help me I have to deliver by Monday.
Thanks, Glen.

Does Anybody Know How To Send An Email Which Includes Message Body?

I have an Excel file which I want to incorporate macros and VB to automatically format a report, and then email out. It's all working well apart from the fact that I can't seem to be able to include a message body in the email. At the moment, I have a 'Send' button, which uses the following code to save one particular sheet of the workbook (the sheet that contains the report) as a seperate Excel file and then email it.

Public Sub SendIBM()
Dim strDate As String
Sheets("IBM Options").Copy
strDate = Format(Date, "dd-mm-yy")
ActiveWorkbook.SaveAs "IBM Options Backlog " & strDate & ".xls"
ActiveWorkbook.SendMail Sheet1.txtEmailTo.Text, "IBM Options Backlog " & strDate
End Sub

On searching google I found this post

which seems to solve the problem for another user - but could anybody help me modify this code to work with my file? Please bear in mind that my VBA skills are pretty basic, and have only got the program working as well as it does with a lot of others people help, so if anybody can assist please can you talk in plain English with clear instructions for me?

Many thanks in advance,


OUTLOOK 2K/VBA Problems To Access The Email Body
Hi Dev fellows,
I am trying to grab the body of an bounced email, flagged whit a System administrator subject, using VBA.

The body of this email look like this:
....there is the email address too
Your message did not reach some or all of the intended recipients.
Subject:Web Survey (6/11/2003)
Sent: 6/11/2003 12:00 AM

The following recipient(s) could not be reached:
'' on 6/11/2003 12:09 AM
Unable to deliver the message due to a communications failure
The MTS-ID of the original message is: c=us;a= ;p=interim healthca;l=IHCMSX010306110408M2W1LN0R
MSEXCH:IMS:Interim HealthCare:IHC:IHCMSX01 3902 (000B09B6) Host Unknown
Example at


However after use:
objMail.SaveAs MyPath & MyFileName, olTXT

A new text file is created with the from, To, and Subject fields, not the body...
However for any other message I get the to, from, subject and body field.

Question: Is any reason why the body field is not been grabbed? However, if I do it manually trough File|SaveAs|as .txt file, the body part gets saved in the TXT file....

Thanks for your help pals!

Attaching File Link To Body Of An Email
I am using the VB editor within Microsoft Outlook to make an attachment stripper. I am trying to insert hyperlink to the location of where the file was saved to within the body of the email.

Does anyone know how to do this?

I tried to use the following line of code

StrmyFileLocation = "C:Documents and Settings
lellisMy Documents<file name here>
myItem.Body = myItem.Body & "file://" & StrmyFileLocation

The problem is that this creates a hyperlink but only to the point where there is a space. Therefore everything after "Documents" in the string does not get converted into the link.

I found out that whan you manually type file://filename within quotation marks the spaces are recognized.

However it doesn't seem to work when inserting a string in quotes in a VB macro as shown below:

myItem.Body = myItem.Body & Chr(34) & "file://" & StrmyFileLocation & Chr(34)

Everything after the space is not recognized.

Copyright © 2005-08, All rights reserved