使用Excel VBA进行电子邮件和签名格式设置

时间:2018-01-15 10:04:49

标签: vba excel-vba email outlook excel

我已经编写了我需要的宏,并且我坚持了一个简单的问题"。电子邮件格式以及签名格式。签名是纯文本的,但在outlook中使用不同的文本颜色和字体进行格式化。

我有以下代码,它以下列格式给我发送电子邮件:

email TITUS classification

Body of the email

Signature

Attachment 

代码

Sub mail()

    Dim wkb As Excel.Workbook
    Dim wks As Excel.Worksheet

    Set wkb = Excel.Workbooks("macro.xlsm")
    Set wks = wkb.Worksheets("settings")

    Dim OApp As Object, OMail As Object, signature As String
    Dim OStrTITUS As String
    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)
        With OMail
        .display
        signature = OMail.body
        .To = "mymail@mail.com"
        .Subject = "Type your email subject here"
        .Attachments.Add ActiveWorkbook.FullName
        .body = "My email body" & vbNewLine & signature
        .display
        SendKeys "{DOWN}{DOWN}{ENTER}", True 'set classification
        SendKeys "{ENTER}", True 'send to group
        .Send
        End With
Set OMail = Nothing
Set OApp = Nothing
End Sub

但我希望Outlook中的附件位于电子邮件的正文中,因此布局将是这样的

Body of the email

Attachment

Signature

1 个答案:

答案 0 :(得分:1)

您可以尝试按照@Niton

的代码修改以下格式
Visual Studio Command Prompt