首页 > 解决方案 > 更改通过 VBA 生成的 Outlook 电子邮件签名的字体大小

问题描述

我可以使签名加粗,但我不能改变大小。我也可以更改正文的大小,但不能更改签名。我需要更改签名的字体大小以匹配电子邮件中正文的字体大小。

Sub Email_Test()

'Exit function if user input incomplete:
If IsNull(Forms!frmCompMain!cboPayPrd) = True Then
            MsgBox "Please provide the Pay Period parameter!", vbCritical
            Exit Sub
            End If

'-----------------------------------------
----'DECLARE AND SET VARIABLES


 Dim myOutlok As Object
    Dim myMailItm As Object
    Dim Signature As String
    Dim OtlApp As Object
    Dim OtlNewMail As Object
    Dim olMailItem As Object
    Dim PayPrd As String


    Set OtlApp = CreateObject("Outlook.Application")
    Set OtlNewMail = OtlApp.CreateItem(0)


    PayPrd = Forms!frmCompMain!cboPayPrd
'-----------------------------------------
-----'GET DEFAULT EMAIL SIGNATURE


Signature = Environ("appdata") & "\Microsoft\Signatures\"
    If Dir(Signature, vbDirectory) <> vbNullString Then
        Signature = Signature & Dir$(Signature & "*.htm")
    Else:
        Signature = ""
    End If
    Signature = 



CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

'-----------------------------------------
----'CREATE EMAIL


OtlNewMail.HTMLBody = Signature
    With OtlNewMail
    .to = ""
    .CC = ""
    .Subject = ""
    .HTMLBody = "<font size='2'> Hello," & "<br />" & _
    "<br />" & _
    "" & "<br />" & _
    "<br />" & _
    "<b>Production Period:</b> " & DateSerial(Year(PayPrd)" & _
    "<br />" & _
    "<b> Pay Date:</b> " & DateSerial(Year(PayPrd), Month(PayPrd) + 1, 10) & 
    "<br />" & _
    "<br />" & _
    "Please let me know if you have any questions." & "<br />" & _
    "<br />" & _
    "<b>" & Signature & "</b>"
    .display
    '.Send
    End With
'-----------------------------------------
----'CLEANUP


End Sub

标签: ms-accessoutlookvba

解决方案


首先,您不能连接两个 HTML 字符串并期望返回一个有效的 HTML 字符串。两者必须合并。

其次,如果在 HTML 签名中明确设置了字体大小,那么将签名明确包装在具有指定字体大小的元素中的代码将无济于事。您需要使用 HTMLDocument 接口或 Word 对象模型来设置大小。

或者,最简单的解决方案是确保固定签名已经具有正确的字体。


推荐阅读