How to include formatted text in the body of an Outlook invite from Excel

前端 未结 1 597
死守一世寂寞
死守一世寂寞 2021-01-17 02:01

I would like to insert text with format (links, bold, highlighted...) in an Outlook invite using Excel VBA.

I have a program that send invites from Excel. The body c

相关标签:
1条回答
  • 2021-01-17 02:50

    Try this:

    Sub SetApptWithHTMLContent()
    
        Dim olapp As Outlook.Application, appt As Outlook.AppointmentItem
        Dim m As Outlook.MailItem
        Dim rtf() As Byte
    
        Set olapp = New Outlook.Application
        Set m = olapp.CreateItem(olMailItem)
        Set appt = olapp.CreateItem(olAppointmentItem)
    
        appt.Subject = "Meeting request"
        '...set other appointment properties
        appt.Display
        'put the HTML into the mail item, then copy and paste to appt
        m.BodyFormat = olFormatHTML
        m.HTMLBody = Range("A1").Value 'sample HTML stored in a cell
        m.GetInspector().WordEditor.Range.FormattedText.Copy
        appt.GetInspector().WordEditor.Range.FormattedText.Paste
        m.Close False 'don't save...
    
    End Sub
    

    Sample HTML:

      <h1>Title Here</H1>
    	<span style='background-color: #ffff00'>Table of stuff:</span><br>
    	<table>
    	<tr>
    		<td style='background-color: #ff9900'>One</td>
    		<td>Two</td>
    	</tr>
    	<tr>
    		<td>Three</td>
    		<td>Four</td>
    	</tr>
    	</table>

    Final appointment body:

    0 讨论(0)
提交回复
热议问题