【发布时间】:2020-05-02 14:00:45
【问题描述】:
我在发送一封带有 jpg 附件的电子邮件时遇到问题,该附件应在文本之前居中位于顶部。
EmailBody 是在此上游定义的,Target 只是 Excel 工作表中的一个名称(此宏是从另一个遍历范围的宏调用的)。
我认为问题在于我如何声明 Outlook 对象。在Set oAttach = colAttach.Add("C:\Users\urdearboy\Desktop\@\Meme.jpg") 出现当前错误(一旦删除On Error Go To 行)
知道我哪里出错了吗?在 Outlook 对象/属性方面没有非常丰富的经验,并试图关注here 的帖子,但没有运气
Sub Sender(EmailBody As String, Target As Range)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim OutApp As Object
Dim OutMail As Object
On Error GoTo BNP:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set colAttach = OutMail.Attachments
Set oAttach = colAttach.Add("C:\Users\urdearboy\Desktop\@\Meme.jpg")
Set olkPA = oAttach.PropertyAccessor
olkPA.SetProperty PR_ATTACH_CONTENT_ID, "Meme.jpg"
With OutMail
.SentOnBehalfOfName = "urdearboy@so.com"
.to = Target.Offset(0, 1)
.cc = Target.Offset(0, 2)
.Subject = "Check Out This Meme " & Target.Offset(0, 3)
.HTMLBody = "<p style = 'font-family:arial' >" _
& "<BODY><CENTER><IMG src =""cid:Meme.jpg""></CENTER></BODY>" _
& "Hi " & Target.Offset(0, 0) & ", " & "<br>" _
& EmailBody & "</p>" _
& "<p style = 'font-family:arial' >" & "<br>" & "Thanks, " & "<br>" _
& "urdearboy" & "</p>"
'Change to .Send to actually send emails
.Display
Target.Offset(, -1) = "Sent"
End With
BNP:
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
【问题讨论】: