简体   繁体   English

Outlook邮件正文为空

[英]Outlook mail body is blank

I have the following to send an email, with a range of cells from my Excel sheet. 以下是我要发送的电子邮件,其中包含Excel工作表中的一系列单元格。

The email is sent with the correct Subject and CC. 电子邮件发送时带有正确的主题和抄送。

There is data in that cell range (A:B) but I cannot get anything in the body. 该单元格区域中有数据(A:B),但我体内什么也看不到。 It stays blank. 它保持空白。

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

the error trapping you have is hiding the error: 13 - Type Mismatch 您所捕获的错误隐藏了错误: 13 - Type Mismatch

you will have to construct the .Body by looping through the values 您将需要通过遍历值来构造.Body

Here's the code to loop through: 这是循环代码:

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")

Try changing 尝试改变

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM