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

问题描述 投票:1回答:2

我能够使签名大胆,但我无法改变大小。我也可以改变身体的大小而不是签名。我需要更改签名的字体大小以匹配电子邮件中正文的字体大小。

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
vba outlook access-vba
2个回答
0
投票

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

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

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


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接口来设置大小。

© www.soinside.com 2019 - 2024. All rights reserved.