L'exemple Microsoft Visual Basic/Visual Basic pour Applications (VBA) suivant montre comment créer un objet MailItem et définir la propriété BodyFormat sur la valeur olFormatHTML. Le corps de texte de l'élément de messagerie électronique apparaît alors au format HTML.
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
'Create e-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>Please enter the message text here. </BODY></HTML>"
.Display
End With
End Sub
Dim CurrFile As Object
Dim s As String, i As Long
For i = 2 To 4
s = s & Cells(i, 1).Value & "; "
Next i
s = Left$(s, Len(s) - 2)
msg.To = s
msg.BCC = s
Sub envoi_Feuille_REV_3()
' Avant de lancer cette macro : Dans l'éditeur VBA, faire
' Menu / Outils / Références... /
' et cocher "Microsoft Outlook 11.0 Object Library"
Dim répertoireAppli As String, olapp As New Outlook.Application, msg As MailItem, s As String
Application.ScreenUpdating = False
répertoireAppli = ActiveWorkbook.Path
Sheets("plongée journalière ").Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs répertoireAppli & "\Plongée du jour.xls"
Application.DisplayAlerts = True
ActiveWindow.Close
Application.ScreenUpdating = True
Sheets("Destinataires").Activate
Range("A11").Select
Do While Not IsEmpty(ActiveCell)
s = s & ActiveCell.Value & "; "
ActiveCell.Offset(1, 0).Select
Loop
s = Left$(s, Len(s) - 2)
Set msg = olapp.CreateItem(olMailItem) ' Envoi par mail
msg.To = s
msg.Subject = Range("A2").Value
msg.Body = Range("A5").Value & Chr(13) & Chr(13) & Range("A8").Value & Chr(13) & Chr(13)
msg.Attachments.Add répertoireAppli & "\Plongée du jour.xls"
msg.Send
End Sub