如何在电子邮件中嵌入 PDF 文档 [英] How to Embed a PDF Document in an Email Message

查看:77
本文介绍了如何在电子邮件中嵌入 PDF 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 PDF 嵌入到我的电子邮件正文中.

我尝试了以下代码,但它一直打开word,但附加了pdf 文件,但没有将pdf 作为对象嵌入到电子邮件正文中.对此的任何帮助将不胜感激.

公共子 CreateNewMessage()将 objMsg 调暗为 MailItem设置 objMsg = Application.CreateItem(olMailItem)使用 objMsg.To = "test@tst.com".Subject = "这是主题".BodyFormat = olFormatHTML.Attachments.Add ("C:WorkDashbaord.pdf"), olOLE '附加 PDF 文件'嵌入PDF设置 wordapp = CreateObject("word.Application")wordapp.Documents.Open FileName:="C:Work" &仪表板.pdf"wordapp.Visible = True'嵌入PDFwordapp.Visible = True设置 wordapp = GetObject(, "Word.Application")wordapp.Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.11", _FileName:="C:WorkDashbaord & ".pdf", LinkToFile:=False, _DisplayAsIcon:=False.展示结束于设置 objMsg = 无结束子

解决方案

应该是这样的.

公共子InsetObject()Dim Inspector 作为 Outlook.Inspector将 wdDoc 变暗为 Word.DocumentDim 选择作为 Word.Selection将电子邮件调暗为 Outlook.mailitem设置电子邮件 = Application.CreateItem(olMailItem)用电子邮件.To = "0m3r@Email.com".subject = "这是主题".Attachments.Add ("C:TempTempFile.pdf").展示设置 Inspector = Application.ActiveInspector()设置 wdDoc = Inspector.WordEditor设置选择 = wdDoc.Application.SelectionSelection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.DC", _文件名:="C:TempTempFile.pdf", _LinkToFile:=False, DisplayAsIcon:=False结束于设置检查员 = 无设置 wdDoc = 无设置选择 = 无结束子

<小时><块引用>

<小时><块引用>

InlineShapes.AddOLEObject方法(词)

创建一个 OLE 对象.返回 InlineShape表示新 OLE 对象的对象.

<小时>

InlineShape 对象 (Word)

代表文档文本层中的一个对象.内嵌形状只能是图片、OLE 对象或 ActiveX 控件.InlineShape 对象是 InlineShapes 集合的成员.InlineShapes 集合包含在文档、范围或选择中内嵌显示的所有形状.InlineShape 对象被视为字符,并被定位为一行文本中的字符.

<小时>

对 Microsoft Word xx.x 对象库的引用

I am trying embed PDF into body of my email .

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:WorkDashbaord.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:WorkDashbaord & ".pdf", LinkToFile:=False, _
        DisplayAsIcon:=False

  .Display
End With

Set objMsg = Nothing
End Sub

解决方案

Should be something like this.

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:TempTempFile.pdf")
        .Display

         Set Inspector = Application.ActiveInspector()
         Set wdDoc = Inspector.WordEditor
         Set Selection = wdDoc.Application.Selection

         Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.DC", _
                   FileName:="C:TempTempFile.pdf", _
                   LinkToFile:=False, DisplayAsIcon:=False

    End With

    Set Inspector = Nothing
    Set wdDoc = Nothing
    Set Selection = Nothing
End Sub



InlineShapes.AddOLEObject Method (Word)

Creates an OLE object. Returns the InlineShape object that represents the new OLE object.


InlineShape Object (Word)

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.


Reference to Microsoft Word xx.x Object Library

这篇关于如何在电子邮件中嵌入 PDF 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆