Outlook邮件正文为空

时间:2012-06-21 17:06:24

标签: excel vba

我有以下内容发送电子邮件,其中包含Excel表格中的一系列单元格。

电子邮件将与正确的主题和CC一起发送。

在那个细胞范围内有数据(A:B),但身体里面无法得到任何东西。它保持空白。

Sub SendEmail()

SendEmail Macro

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
    .To = Sheets("Test1").Range("F2").Value
    .CC = Sheets("Test1").Range("F3").Value
    .BCC = ""
    .Subject = Sheets("Test1").Range("E1").Text
    .Body = Sheets("Test1").Range("A:B")
    .Send
End With
On Error GoTo 0

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

2 个答案:

答案 0 :(得分:1)

您遇到的错误陷阱隐藏了错误:13 - Type Mismatch

您必须通过循环遍历值

来构建.Body

这是循环的代码:

Dim I As Long
Dim LastRowColA As Long
Dim BodyString As String

BodyString = ""
LastRowColA = Sheets("Test1").Range("A65536").End(xlUp).Row
For I = 1 To LastRowColA
    BodyString = BodyString & Sheets("Test1").Range("A" & I).Value & vbTab & Sheets("Test1").Range("B" & I).Value & vbCrLf
Next I
.Body = BodyString ' instead of = Sheets("Test1").Range("A:B")

答案 1 :(得分:0)

尝试更改

Sheets("Test1").Range("E1").Text 

Sheets("Test1").Range("E1").Value