VBA,在vba代码中插入outlook签名
我有一个vba代码,当到期日期距离当前日期至少7天7天时,自动发送电子邮件。问题是他们在没有我的Outlook签名的情况下发送电子邮件。我使用Outlook 2016. 如果你能帮助我,这对我来说将是一个很大的帮助。VBA,在vba代码中插入outlook签名
的代码是:
Sub email()
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
Sheets(1).Select
lRow = Cells(Rows.Count, 4).End(xlUp).Row
For i = 2 To lRow
toDate = Cells(i, 3)
If toDate - Date <= 7 Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
toList = Cells(i, 4) 'gets the recipient from col D
eSubject = "Doukementacion per " & Cells(i, 2) & " Targa " & Cells(i, 5)
eBody = "Pershendetje Adjona" & vbCrLf & vbCrLf & "Perfundo dokumentacionin e nevojshem per " & Cells(i, 2) & " me targa " & Cells(i, 5)
On Error Resume Next
With OutMail
.To = toList
.CC = ""
.BCC = ""
.Subject = eSubject
.Body = eBody
.bodyformat = 1
'.Display ' ********* Creates draft emails. Comment this out when you are ready
.Send '********** UN-comment this when you are ready to go live
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Cells(i, 11) = "Mail Sent " & Date + Time 'Marks the row as "email sent in Column A"
End If
Next i
ActiveWorkbook.Save
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
谢谢!
我发现有用的是使它成为HTMLBody
。所以这部分:
With OutMail
.To = toList
.CC = ""
.BCC = ""
.Subject = eSubject
.Body = eBody
.bodyformat = 1
'.Display ' ********* Creates draft emails. Comment this out when you are ready
.Send '********** UN-comment this when you are ready to go live
End With
会是什么样子
With OutMail
.Display 'ads the signature
.To = toList
.Subject = eSubject
.HTMLBody = eBody & .HTMLBody
'.Display ' ********* Creates draft emails. Comment this out when you are ready
.Send '********** UN-comment this when you are ready to go live
End With
您可能需要切换事件,不知道,因为我没有禁用
这是错误的 - 你不能连接2个HTML文件并产生一个有效的HTML文件 - 你的数据需要在适当的地方插入到HTML主体中。 –
它的工作原理,但可能是我用这个一年左右的运气,或者我错过了'身体'的东西。从https://www.rondebruin.nl/win/s1/outlook/signature.htm找到灵感来源:http://www.rondebruin.nl/win/s1/outlook/signature.htm – krib
它在那个链接上工作,因为被附加的数据不是一个带有html和head标签的完整的HTML文档。在你的情况下,你是在有效的HTML文档开始之前追加数据。如果Outlook可以解析出来,你很幸运。通常情况并非如此。 –
可能的重复事件检测[如何添加默认在Outlook中签名](https://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook) – niton