此处添加两个前期绑定,
Microsoft Outlook 16.0 Object Library
Microsoft Word 16.0 Object Library
此处为什么要对Word进行前期绑定引用呢?因为邮件的正文其实是一个Word文档页面。我们可以像写入Word那样进行书写邮件,如果你会Word VBA,那么今天这个问题就很简单啦。
二、代码
Sub InsertImageToEmailBody2()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olRange As Word.Range
Dim olShape As Word.InlineShape
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
Set olInspector = olMail.GetInspector
Set olDocument = olInspector.WordEditor
Set olRange = olDocument.Content
olMail.Display
With olDocument.Application.Selection
.Text = "Hello!!" & Chr(10) & "以下是拾柒的微信二维码" & Chr(10) & Chr(13)
.EndKey
Set olShape = .InlineShapes.AddPicture("C:\Users\jares\Pictures\联想截图\联想截图_20230328204905.png")
.EndKey
.Text = Chr(10) & Chr(13) & "如有需要定制或答疑可添加"
End With
With olMail
.To = "jaresfzz@163.com"
.Subject = "这是一封带图片的测试邮件"
.Send
End With
End Sub
如果我们调试完毕,也可将文中的代码改为后期绑定,好了,下面我们来看看效果。
好了,本期教程就到这里啦,走过路过的点个关注分享一下吧,谢谢啦