locked
HTML instead of Plain Text RRS feed

  • Question

  • ‘DoCmd.SendObject acSendReport …' is working fine in my Access VBA-code to create a new Email in my Outlook 2010, but the format is ‘Plain Text’. I rather would prefer ‘HTML’-format (to insert Signatures) instead of ‘Plain Text’. Is there a possibility (parameter?) to do it in VBA?

    • Moved by Mark Liu-lxf Thursday, October 11, 2012 3:51 AM (From:Visual Basic General)
    Wednesday, October 10, 2012 4:00 PM

Answers

  • Hi Luc,

    Welcome to the MSDN forum.

    Do you mean the Email body of the message? We can't specify an Email body in HTML format via SendObject method. However, We can send a HTML email via Outlook automation. Please take a look at the following method: 

     Please check the reference for Microsoft Outlook 14.0 object library for outlook 2010.
    Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
        Dim objOutlook As Outlook.Application
        Dim objOutlookMsg As Outlook.MailItem
        Dim objOutlookRecip As Outlook.Recipient
        Dim objOutlookAttach As Outlook.Attachment
        
        ' Create the Outlook session.
        Set objOutlook = CreateObject("Outlook.Application")
              
        ' Create the message.
        Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
        
        With objOutlookMsg
            ' Add the To recipient(s) to the message.
            Set objOutlookRecip = .Recipients.Add("test@test.com")
            objOutlookRecip.Type = olTo
    
            ' Set the Subject, Body, and Importance of the message.
            .Subject = "This is an Automation test with Microsoft Outlook"
            .Body = "This is the body of the message." & vbCrLf & vbCrLf
    
            ' Speficy the body format
            .BodyFormat = olFormatHTML
            
            .Importance = olImportanceHigh  'High importance
            
            
            ' Add attachments to the message.
            If Not IsMissing(AttachmentPath) Then
            Set objOutlookAttach = .Attachments.Add(AttachmentPath)
            End If
    
            ' Resolve each Recipient's name.
            For Each objOutlookRecip In .Recipients
                objOutlookRecip.Resolve
            Next
            
            ' Should we display the message before sending?
            If DisplayMsg Then
                .Display
            Else
                .Save
                .Send
            End If
        End With
         
        Set objOutlook = Nothing
        
    End Sub

    Reference from: 
    Using Automation to Send a Microsoft Outlook Message
    http://support.microsoft.com/?kbid=161088 

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Dummy yoyo Friday, November 2, 2012 5:58 AM
    Thursday, October 11, 2012 7:19 AM

All replies

  • Hi,

    You can use the third parameter as "acFormatHTML" to sent HTML emails.

    More on sendobject http://www.fmsinc.com/microsoftaccess/email/sendobject.html


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    Wednesday, October 10, 2012 4:04 PM
  • FYI, this question probably belongs in the Access for Developers forum. This forum is primarily for Visual Basic .NET.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, October 10, 2012 6:06 PM
  • Hi Luc,

    Welcome to the MSDN forum.

    Do you mean the Email body of the message? We can't specify an Email body in HTML format via SendObject method. However, We can send a HTML email via Outlook automation. Please take a look at the following method: 

     Please check the reference for Microsoft Outlook 14.0 object library for outlook 2010.
    Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
        Dim objOutlook As Outlook.Application
        Dim objOutlookMsg As Outlook.MailItem
        Dim objOutlookRecip As Outlook.Recipient
        Dim objOutlookAttach As Outlook.Attachment
        
        ' Create the Outlook session.
        Set objOutlook = CreateObject("Outlook.Application")
              
        ' Create the message.
        Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
        
        With objOutlookMsg
            ' Add the To recipient(s) to the message.
            Set objOutlookRecip = .Recipients.Add("test@test.com")
            objOutlookRecip.Type = olTo
    
            ' Set the Subject, Body, and Importance of the message.
            .Subject = "This is an Automation test with Microsoft Outlook"
            .Body = "This is the body of the message." & vbCrLf & vbCrLf
    
            ' Speficy the body format
            .BodyFormat = olFormatHTML
            
            .Importance = olImportanceHigh  'High importance
            
            
            ' Add attachments to the message.
            If Not IsMissing(AttachmentPath) Then
            Set objOutlookAttach = .Attachments.Add(AttachmentPath)
            End If
    
            ' Resolve each Recipient's name.
            For Each objOutlookRecip In .Recipients
                objOutlookRecip.Resolve
            Next
            
            ' Should we display the message before sending?
            If DisplayMsg Then
                .Display
            Else
                .Save
                .Send
            End If
        End With
         
        Set objOutlook = Nothing
        
    End Sub

    Reference from: 
    Using Automation to Send a Microsoft Outlook Message
    http://support.microsoft.com/?kbid=161088 

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Dummy yoyo Friday, November 2, 2012 5:58 AM
    Thursday, October 11, 2012 7:19 AM