我正在尝试将PDF嵌入到我的电子邮件正文中。
我尝试了以下代码,但它会保持打开单词但附加pdf
文件,但不会将pdf
作为对象嵌入电子邮件正文中。任何有关这方面的帮助将不胜感激。
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
答案 0 :(得分:1)
应该是这样的。
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
<强> InlineShapes.AddOLEObject Method (Word) 强>
创建一个OLE对象。返回表示新OLE对象的 InlineShape 对象。
<强> InlineShape Object (Word) 强>
表示文档文本图层中的对象。内联形状只能是图片,OLE对象或ActiveX控件。 InlineShape对象是InlineShapes集合的成员。 InlineShapes集合包含在文档,范围或选择中内嵌显示的所有形状。 InlineShape对象被视为字符,并在一行文本中定位为字符。
对Microsoft Word xx.x对象库的引用