首页 > 解决方案 > vba Outlook 在内容和签名之间添加换行符

问题描述

嗨,在粘贴表格和签名后尝试在我的正文内容之间添加换行符,代码如下:

dim FileName As String
Dim filepath As String
Dim rng As Range
Dim OutlookApp As Object
Dim Outlookmail As Object
Dim lastrowo As Integer
Application.ScreenUpdating = False
Set OutlookApp = CreateObject("Outlook.Application")
Set Outlookmail = OutlookApp.CreateItem(0)
lastrowo = Worksheets("Price And Accrued Info").Range("K550").End(xlUp).row
Set rng = Worksheets("Price And Accrued Info").Range("K2:y" & lastrowo)
rng.Copy
Dim vInspector As Object
Set vInspector = Outlookmail.GetInspector

Dim wEditor As Object
Set wEditor = vInspector.WordEditor

With Outlookmail


    .To = ""
    .cc=""
    .Subject = "UNCONFIRMED TRADES AS OF " & Format$(Date, "YYYY.MM.DD")
    wEditor.Paragraphs(1).Range.Text = "Hi The following trades are unconfirmed trades."

    wEditor.Paragraphs(2).Range.Paste

    wEditor.Paragraphs(4).Range.Text = vbNewLine & "<br>"


    .display
  ' .attachments.Add drWorkbook.FullName
  ' .attachments.Add crWorkbook.FullName
  '
End With

Set Outlookmail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True

标签: vbahtml-email

解决方案


尝试这个:

With Outlookmail
    .To = ""
    .cc = ""
    .Subject = "UNCONFIRMED TRADES AS OF " & Format$(Date, "YYYY.MM.DD")
    wEditor.Paragraphs(1).Range.Text = "Hi The following trades are unconfirmed trades." _
        & String(5, vbNewLine)
    wEditor.Paragraphs(5).Range.Text = "This is is the last line." _
        & vbNewLine & vbNewLine
    wEditor.Paragraphs(3).Range.Paste
    .display
End With

推荐阅读