将范围插入电子邮件正文

时间:2016-12-29 20:41:34

标签: vba excel-vba excel

我试图编写一个宏,它将获取一系列单元格并将其输出到某个文本之间的电子邮件中。

我无法确定如何插入范围。我不确定问题是我的范围是否未正确声明,或者我没有正确调用它。

目前我有:

Sub Email()

Dim OutApp As Object
Dim OutMail As Object
Dim Body As String
Dim Rng As Range

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set Rng = ActiveWorkbook.ActiveSheet.Range("A7", Range("A7").End(xlDown))

Body = "Hello," & vbNewLine & vbNewLine & _
        "Some text, followed by numbers:" & vbNewLine & vbNewLine & _
        Rng & vbNewLine & _
        "More text"

On Error Resume Next
With OutMail
    .Body = Body
    .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

1 个答案:

答案 0 :(得分:-1)

除非您可以将数据连接成字符串,否则您必须将其作为附件发送。

Ron deBruin为此提供了很多代码。您需要对其进行调整以添加文字。

http://www.rondebruin.nl/win/s1/outlook/amail4.htm