1

让宏运行并很好地刮取姓名和邮件地址,但我无法让发送的 mial 中的文本出现在不同的行上,它显示为一长行文本。我尝试添加 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

结束子

4

1 回答 1

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"
于 2013-08-08T17:12:33.347 回答