PDA

View Full Version : Solved: Change email body text to HTML



DLancy
06-08-2004, 08:01 AM
I am a DBA/Programmer and I am creating a template maker for the developers to submit db changes to me via Outlook using a custom form and vba. I can create the template, but I want to either (or possibly both) bold the key words or italicize the spots they need to replace. Also changing the comment lines to another color would be nice. I know HTML, so if I could force them to use HTML to create the message, that would work. Otherwise I'll need to know if they're using RTF or HTML and be able to make those changes with RTF. Thanks for the help.

- Doug

======= CODE SNIPPET ========

Sub InsertButton_click()
'Add SQL Template for an Insert Clause
TableName = UCase(InputBox("Table Name?", "INSERT", lastTable))
DRNumber = InputBox("DR Number? (Leave Blank for none.)", "INSERT", lastDR)
BodyText = InsertHeader(TableName, DRNumber)
BodyText = BodyText + "INSERT INTO " + TableName + " ( ColumnNames ) VALUES ( Values );" + vbNewLine
BodyText = BodyText + vbNewLine + "/*---------------------------------------------------------------*/" + vbNewLine + vbNewLine
Item.Body = Item.Body + BodyText
End Sub

jamescol
06-08-2004, 08:15 AM
You can use this procedure to create a new HTML mail from within your code:
(tested with Office 2003)


Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

Dim olApp As Outlook.Application
Dim objMail As MailItem
Set olApp = Outlook.Application
'Create mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With

End Sub

DLancy
06-08-2004, 08:52 AM
Thanks!

Although what you said won't work as I'm already within the form, it gave me what I needed to force it into HTML. Instead of setting the Item.Body, I set the Item.HTMLBody and voila HTML document!

VBA:

Sub InsertButton_click()
'Add SQL Template for an Insert Clause
TableName = UCase(InputBox("Table Name?", "INSERT", lastTable))
DRNumber = InputBox("DR Number? (Leave Blank for none.)", "INSERT", lastDR)
BodyText = InsertHeader(TableName, DRNumber)
BodyText = BodyText + "<b>INSERT INTO</b> " + TableName + " ( <i>ColumnNames</i> ) VALUES ( <i>Values</i> );<br/>"
BodyText = BodyText + "<br/>/*---------------------------------------------------------------*/<br/><br/>"
Item.HTMLBody = Item.HTMLBody + BodyText
End Sub

jamescol
06-08-2004, 01:03 PM
Cool! Glad we were able to help point you to the solution. I'll mark this thread resolved.

Let us know if we can help with anything else.

Cheers,
James