首页 文章

Outlook邮件正文为空

提问于
浏览
0

我有以下内容发送电子邮件,其中包含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

    您捕获的错误是隐藏错误: 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

    尝试改变

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

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

相关问题