How to send email with HTML email body in Excel?
If you want to send an email with HTML format body content in Excel, a method in this article can help you.
Enable you to do smarter, faster and better
Please do as follows to send an email with HTML format body content in Excel.
1. Press the Alt + F11 simultaneously to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy below VBA code into the Module window.
VBA code: Send email with HTML email body in Excel
Sub SendEmailformattext() 'Update by Extendoffice.com Dim xRg As Range Dim xRgEach As Range Dim xRgVal As String Dim xAddress As String Dim xOutApp As Outlook.Application Dim xMailOut As Outlook.MailItem On Error Resume Next xAddress = ActiveWindow.RangeSelection.Address Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8) If xRg Is Nothing Then Exit Sub Application.ScreenUpdating = False Set xOutApp = CreateObject("Outlook.Application") Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues) For Each xRgEach In xRg xRgVal = xRgEach.Value If xRgVal Like "?*@?*.?*" Then Set xMailOut = xOutApp.CreateItem(olMailItem) With xMailOut .Display .To = xRgVal .Subject = "Test" .HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Font Color</span style=""color:#80BFFF""> <br>the <b>bold text</b> here.</br> <br><u>New line with underline</u></br><br><p style='font-family:calibri;font-size:25'>Font size</br></p></BODY></HTML>" '.Send End With End If Next Set xMailOut = Nothing Set xOutApp = Nothing Application.ScreenUpdating = True End Sub
1) Replace the .Subject line with your own one.
2) In the .HTMLBody line:
2.1) <span style=""color:#80BFFF"">...</span style=""color:#80BFFF""> is the text color format;
2.2) <b>…</b> can make your text bold;
2.3) If you want to start a new line, please enclose the new line text with <br>…</br>;
2.4) Underline your text with <u>…</u>;
2.5) And change your text size by <p style='font-family:calibri;font-size:25'>…</p>.
3. Click Tools > References, check the Microsoft Outlook Object Library box in the References – VAProject dialog box, and then click the OK button. See screenshot:
4. Press the F5 key to run the code. In the popping up Kutools for Excel dialog box, select the recipients’ email addresses and then click the OK button.
Then email with specified fields and HTML body is created. Please click the Send button to send it.
- How to automatically send email based on cell value in Excel?
- How to insert signature into Outlook email when sending by vba in Excel?
- How to send email with specified bold/size/color/underline text format in Excel?
- How to send email without Outlook in Excel?
- How to send a specific chart in an email with vba in Excel?
- How to send an email at specific time of a day in Excel?