让宏运行并清除名称和邮件地址,但我无法将发送的文本发送到不同的行,它显示为一行长文本。我尝试添加vbline等,但它没有任何区别
在Sub mailtoo()
中Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("b").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "c").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "for Action"
.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"line one of text here. " & _
"line two of text here" & _
"line three of text here" & _
"Regards" & _
"your name"
.Attachments.Add "C:\demofilename.xlsx"
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
清理:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:1)
您需要在任何想要显示新文本行的地方使用VbNewLine
变量:
& vbNewLine & vbNewLine & _
"line one of text here. " & vbNewLine & _
"line two of text here" & vbNewLine & _
"line three of text here" & vbNewLine & vbNewLine &_
"Regards" & vbNewLine & _
"your name"
请记住,VB行继续符_
不会对字符串做任何特殊操作,它只是为了让你的代码本身更具可读性。如果删除行继续,这对运行时没有任何意义,那么原始代码在执行的内容上看起来就像这样:
"line one of text here. " & "line two of text here" & "line three of text here" & "Regards" & "your name"