更改通过VBA生成的Outlook电子邮件签名的字体大小

时间:2018-09-10 19:56:04

标签: vba outlook access-vba

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

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

2 个答案:

答案 0 :(得分:0)

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

第二,如果在HTML签名中显式设置了字体大小,则您的代码将签名明确地包装在具有指定字体大小的元素中将不会执行任何操作。您需要使用HTMLDocument接口或Word对象模型来设置大小。

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

答案 1 :(得分:0)

您应该使用以下代码替换.HTMLBody内容:

Signature = "<b style='color:red;'>Your Sigature</b>"    
With OutMail
        .To = ""
        .Subject = "This is the Subject line"
        .HTMLBody = "<font style='font-size:20px !important;'> Hello <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 style='font-size 14px !important'>" & Signature & "</b></font>"
        .Display

如果在HTML签名中设置了字体大小,则需要使用HTMLDocument接口来设置大小。