在 VBA 中更改 HTML 电子邮件正文字体类型和大小 [英] Change HTML email body font type and size in VBA

查看:97
本文介绍了在 VBA 中更改 HTML 电子邮件正文字体类型和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VBA 脚本,当在给定的工作表中按下 VBA 按钮时,它会生成和发送电子邮件.

I have a VBA script that that generates and email when a VBA button is pushed in a given worksheet.

脚本当前以相对较小的字体生成电子邮件.我想知道是否有办法将字体设置为 Calibri,并将文本设置为 11.

The script currently generates the email in a relatively small font. I was wondering if there is a way to set the font to Calibri, and the text sive to exactly 11.

这是当前的 VBA 脚本:

Here is the current VBA script:

Private Sub CommandButton1_Click()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim strUser As String
Dim signature As String
Dim sTo As String
Dim sCC As String
    'For To field
    Set emailRng = Worksheets("Send Email").Range("D3:I6")

    For Each cl In emailRng
        sTo = sTo & ";" & cl.Value
    Next

    sTo = Mid(sTo, 2)

    'For CC field
    Set emailRngCC = Worksheets("Send Email").Range("D8:I11")

    For Each cl In emailRngCC
        sCC = sCC & ";" & cl.Value
    Next

    sCC = Mid(sCC, 2)


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .Display
    End With
        signature = OutMail.HTMLBody


    strbody = "<FONT SIZE = 3>Good Morning;<p>We have completed our main aliasing process for today.  All assigned firms are complete.  Please feel free to respond with any questions.<p>Thank you."

    With OutMail
        .SentOnBehalfOfName = ""
        .To = sTo
        .CC = sCC
        .BCC = ""
        .Subject = "Data Morning Alias Process - COMPLETE"
        .HTMLBody = strbody & signature
        .Display
    End With
End Sub

我知道这部分代码:

strbody = "<FONT SIZE = 3.5>Good Morning;<p>We have completed our main aliasing

是与电子邮件正文文本大小相关的部分.但是3的设置太小了,4的设置太大了.所以我只是想知道是否有某种方法可以将字体设置为 11 号,并将文本设置为 Calibri 格式?

is the portion that relates to the email body text size. But a setting of 3 is to small, and a setting of 4 is too big. So I was just wondering if there is some way I can set the font to be exactly size 11, and the text to be formatted as Calibri?

谢谢!

推荐答案

我做了一点研究并且能够写出这段代码:

I did a little research and was able to write this code:

strbody = "<BODY style=font-size:11pt;font-family:Calibri>Good Morning;<p>We have completed our main aliasing process for today.  All assigned firms are complete.  Please feel free to respond with any questions.<p>Thank you.</BODY>"

显然是通过设置"font-size=11pt"而不是设置字体大小,它允许您像通常在文本编辑器中一样选择特定的字体大小,而不是像我的代码最初那样从 1-7 中选择一个值.

apparently by setting the "font-size=11pt" instead of setting the font size <font size=5>, It allows you to select a specific font size like you normally would in a text editor, as opposed to selecting a value from 1-7 like my code was originally.

这个来自 simple man 的链接给了我一些很好的信息.

This link from simpLE MAn gave me some good info.

这篇关于在 VBA 中更改 HTML 电子邮件正文字体类型和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆