如何在电子邮件中嵌入PDF文档 [英] How to Embed a PDF Document in an Email Message
问题描述
我正在尝试将PDF嵌入到电子邮件正文中.
I am trying embed PDF into body of my email .
我尝试了下面的代码,但是它保持打开单词,但附加了pdf
文件,但没有将pdf
作为对象嵌入到电子邮件正文中.任何帮助,将不胜感激.
I tried following code but it keeps opening word but attaches pdf
file but does not embed pdf
as a object in the body of email. Any help on this will be appreciated.
Public Sub CreateNewMessage()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.To = "test@tst.com"
.Subject = "This is the subject"
.BodyFormat = olFormatHTML
.Attachments.Add ("C:\Work\Dashbaord.pdf"), olOLE 'Attach PDF File
'Embed PDF
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Open FileName:="C:\Work\" & "Dashbaord.pdf"
wordapp.Visible = True
'Embed PDF
wordapp.Visible = True
Set wordapp = GetObject(, "Word.Application")
wordapp.Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.11", _
FileName:="C:\Work\Dashbaord & ".pdf", LinkToFile:=False, _
DisplayAsIcon:=False
.Display
End With
Set objMsg = Nothing
End Sub
推荐答案
应该是这样的.
Public Sub InsetObject()
Dim Inspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim Selection As Word.Selection
Dim Email As Outlook.mailitem
Set Email = Application.CreateItem(olMailItem)
With Email
.To = "0m3r@Email.com"
.subject = "This is the subject"
.Attachments.Add ("C:\Temp\TempFile.pdf")
.Display
Set Inspector = Application.ActiveInspector()
Set wdDoc = Inspector.WordEditor
Set Selection = wdDoc.Application.Selection
Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.DC", _
FileName:="C:\Temp\TempFile.pdf", _
LinkToFile:=False, DisplayAsIcon:=False
End With
Set Inspector = Nothing
Set wdDoc = Nothing
Set Selection = Nothing
End Sub
创建一个OLE对象.返回 InlineShape 代表新的OLE对象的对象.
表示文档文本层中的对象.嵌入式形状只能是图片,OLE对象或ActiveX控件. InlineShape对象是InlineShapes集合的成员. InlineShapes集合包含在文档,范围或选择中内联显示的所有形状. InlineShape对象被视为字符,并被定位为一行文本中的字符.
Represents an object in the text layer of a document. An inline shape can only be a picture, an OLE object, or an ActiveX control. The InlineShape object is a member of the InlineShapes collection. The InlineShapes collection contains all the shapes that appear inline in a document, range, or selection. InlineShape objects are treated like characters and are positioned as characters within a line of text.
对Microsoft Word xx.x对象库的引用
Reference to Microsoft Word xx.x Object Library
这篇关于如何在电子邮件中嵌入PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!