如何在VBA生成的电子邮件正文中添加其他文本/图像?

时间:2019-05-06 17:37:39

标签: excel vba

当前,vba代码创建一个Outlook电子邮件项目,该项目将Word文档的内容作为其电子邮件正文。如何向身体添加其他文本/图像?

这个SO问题的答案是我如何创建Outlook项目: How to send a Word document as body of an email with VBA

这是我正在使用的实际代码:

Sub email()
Mail_Object, o As Variant

    Dim wd As Object, editor As Object
    Dim doc As Object
    Set wd = CreateObject("Word.Application")
    Set doc = wd.documents.Open("(word address)")
    doc.Content.Copy
    Set wd = Nothing

Set Mail_Object = CreateObject("Outlook.Application")

        With Mail_Object.CreateItem(o)
            .Subject = "subject"
            .To = "to"
            Set editor = .GetInspector.WordEditor
            editor.Content.Paste

            'here something like: body = body & "additional text"
            .Display
        End With

        Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub

2 个答案:

答案 0 :(得分:0)

如果将对象定义为.HTMLBody,则可以使用HTML标记。您可以尝试执行以下操作:

MailItem.HTMLBody = Content & "<br>" & "<br>"
MailItem.HTMLBody = Content &  "<B>" & "<h3>" & "DRAFT: Your Additional Content Here" & "</h3>" & "</B>" & "<br>" & _
"Your Additional Image Here: " & "<br>"&  "<img src="image/url">

答案 1 :(得分:0)

当您命名excel标记时,下面是一些将形状或Excel单元格作为图片添加到电子邮件正文中的示例(没有html知识):

With Editor.Range

    .Collapse wdCollapseStart
    .InsertBefore "Hi there," & vbCrLf & "here's my picture:" & vbCrLf

    .Collapse wdCollapseEnd
    .InsertAfter vbCrLf & "Best wishes," & vbCrLf

    .Collapse wdCollapseStart
    .PasteSpecial link:=False, _
        DataType:=wdPasteShape, _
        Placement:=wdInLine, _
        DisplayAsIcon:=False
    '.Paste
    '.PasteAndFormat wdChartPicture
    '.PasteAndFormat wdFormatPlainText
End With