首页 > 解决方案 > .HTMLBody - 正文和签名之间的间距

问题描述

我刚刚开始使用 VBA 来批量发送电子邮件,但我遇到了一个问题,因为最后一句和签名之间有一条额外的线。

这是它的外观:

尊敬的示例 2 先生,

消息 1

消息 2

恭喜!

空间

空间

签名

我在不同的论坛上进行了研究,但找不到任何解决方案。

预先感谢您对我们的支持!

这是我正在使用的代码:

Option Explicit
Sub Example()
   Dim olApp As Object
   Dim olMail As Object
   Dim olRecip As Object
   Dim olAtmt As Object
   Dim iRow As Long
   Dim Recip As String
   Dim Subject As String
   Dim Atmt As String


   iRow = 2

   Set olApp = CreateObject("Outlook.Application")

   Do Until IsEmpty(Cells(iRow, 1))

      Recip = Cells(iRow, 1).Value
      Subject = Cells(iRow, 3).Value
      Atmt = Cells(iRow, 4).Value ' Attachment Path


      Set olMail = olApp.CreateItem(0)

      With olMail
         Set olRecip = .Recipients.Add(Recip)
        .Display
        .Subject = Subject
        .HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "message 1" & "<br>" & "<br>" & "message 2" & "<br>" & "<br>" & "Congratulations!" & .HTMLbody
         Set olAtmt = .Attachments.Add(Atmt)
         olRecip.Resolve
        .Save
        .Close 1


      End With

      iRow = iRow + 1

   Loop

   Set olApp = Nothing
   Exit Sub

End Sub'

标签: htmlvbaexcel

解决方案


我相信我今天发布了一个有助于解决此问题的答案,您可以在这里找到它 - https://stackoverflow.com/a/70268202/17609669

在此获取签名的代码会删除空格,然后可以使用正常的中断来提供所需的间距。


推荐阅读