+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    05-10-2006
    Posts
    44

    Format text in e-mail body

    Hi

    I want to be able to send a basic e-mail with the body text containing certain words in bold and underlined.

    I have tried to force Outlook 2003 to convert the message to Rich Text or HTML format with no success.

    Please can anyone assist or even tell me if it is possible?

    I have the following code:

    Code:
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2007
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
    
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi Roxanne" & vbNewLine & vbNewLine & _
                  "Sorry for all the e-mails but " & _
                  "I am testing something for Martin." & vbNewLine & vbNewLine & _
                  "Thank you" & vbNewLine & vbNewLine & _
                  "Tom"
    
        On Error Resume Next
        With OutMail
            .To = "test@test.com"
            .CC = ""
            .BCC = ""
            .Subject = "Test for Tom"
            .Body = strbody
            'You can add a file like this
            '.Attachments.Add ("c:\MailBody.txt")
            .Send   'or use .Display
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    End Sub
    Last edited by mabbutt; 09-28-2009 at 07:15 AM.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Format text in e-mail body

    Use HTMLBody and then use standard HTML mark-up, eg:

    Code:
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2007
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
    
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi <b>Roxanne</b>" & vbNewLine & vbNewLine & _
                  "Sorry for all the e-mails but " & _
                  "I am testing <u>something</u> for <i><font color=red>Martin</font></i>." & vbNewLine & vbNewLine & _
                  "Thank you" & vbNewLine & vbNewLine & _
                  "Tom"
    
        On Error Resume Next
        With OutMail
            .To = "test@test.com"
            .CC = ""
            .BCC = ""
            .Subject = "Test for Tom"
            .HTMLBody = strbody
            'You can add a file like this
            '.Attachments.Add ("c:\MailBody.txt")
            .Send   'or use .Display
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    End Sub

  3. #3
    Registered User
    Join Date
    05-10-2006
    Posts
    44

    Re: Format text in e-mail body

    Hi DonkeyOte

    Thank you so much that is great!!

    Would it be possible to use a CSS style sheet instead of the formatting?

    I can do this in normal HTML I just need to know the syntax for Excel.

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Format text in e-mail body

    Re: CSS - no idea... I wouldn't have thought so, no.

    Re: VBA - simply code the HTML mark up into the string as illustrated.

  5. #5
    Registered User
    Join Date
    05-10-2006
    Posts
    44

    Re: Format text in e-mail body - SOLVED

    DonkeyOte

    Thank you!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0