vba - 如何使用 VBA 从 Access 向 Outlook 邮件添加 html 签名?
问题描述
代码发布在这里并被报告可以工作,对我不起作用。
此代码抛出
运行时错误 '287 应用程序定义或对象定义错误
就行了Signature = Outmail.body
。
我想要当前 Outlook 用户的默认签名。
Private Sub Command33_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim currentDate As Date
Dim DeliveryDate As String
Dim Recipients As String
Dim CarbonCopy As String
Dim Signature As Variant
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
currentDate = Format(Date, "dd/mm/yyyy")
Recipients = "a@gmail.com"
CarbonCopy = "b@gmail.com"
Signature = OutMail.Body
'msg hasn't been defined so it's commented out. msg in the body has been replaced with "msg".
'msg = "<span style='color:black'><p>Dear Team,</p>"
'msg = msg & "Thank you in advance</span>"
On Error Resume Next
With OutMail
'Capture signature block.
.Display
Signature = .HTMLBody
.To = Recipients
.CC = CarbonCopy
.Subject = "PSR " & currentDate
.HTMLBody = "<span style = 'color:#1F497D'>" & "msg" & "</span>" & Signature
.Attachments.Add ThisWorkbook.FullName
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
解决方案
如前所述,删除Signature = OutMail.Body
.
然后在 之后放置一个断点Signature = .HTMLBody
,并检查它的值。
这就是我在 Outlook 365 中所做的(它也适用于 Outlook 2010):
' Outlook HTML: after Mailitem.Display, .HtmlBody starts with
' <p class=MsoNormal><o:p> </o:p></p>
' Exactly in this line we want to put our HTML encoded mail text.
oItem.HtmlBody = Replace(oItem.HtmlBody, " ", strMyBody, Count:=1)
默认签名在此行下方,并且保持不变。
编辑:our HTML encoded mail text
意味着:我将纯文本传递给我的函数,并替换vbCrLf
为<br>
.
如果您有实际的 HTML<p>
等等,请改用Jeremy 的答案。
推荐阅读
- javascript - 为什么 dispatch() 正在添加附加属性“未定义”
- python - 将一行中的 for-loop 转录为阶梯式 for-loop
- android - BottomSheetDialog 似乎在 MaterialDesign Library v1.4.0 中有一个错误
- c++ - 如何从类方法对 C++ 中的类进行操作?
- polymorphism - 如何在 Graphql-Java 中处理运行时多态性
- jquery - 页面加载时的 jQuery 下拉菜单
- javascript - 如何附加一个包含内部内容的子 div
- spring-boot - 为什么我们在开发 REST API 时使用 @RequestHeader 注解?
- c++ - 为什么我的字符串没有在函数中打印?
- php - 在 mysql 中设置一个唯一列并在 codeigniter 中显示 flashdata