Consulting

Results 1 to 4 of 4

Thread: Solved: Change email body text to HTML

  1. #1

    Lightbulb Solved: Change email body text to HTML

    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 ========

    [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 + "INSERT INTO " + TableName + " ( ColumnNames ) VALUES ( Values );" + vbNewLine
    BodyText = BodyText + vbNewLine + "/*---------------------------------------------------------------*/" + vbNewLine + vbNewLine
    Item.Body = Item.Body + BodyText
    End Sub
    [/vba]
    Last edited by DLancy; 06-08-2004 at 01:57 PM.

  2. #2
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    You can use this procedure to create a new HTML mail from within your code:
    (tested with Office 2003)

    [vba]
    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
    [/vba]
    "All that's necessary for evil to triumph is for good men to do nothing."

  3. #3
    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:
    [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
    [/vba]
    Last edited by jamescol; 06-08-2004 at 12:59 PM. Reason: add vba tags

  4. #4
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    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
    "All that's necessary for evil to triumph is for good men to do nothing."

Posting Permissions

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