【问题标题】:Adding PDF to Outook将 PDF 添加到 Outlook
【发布时间】:2018-06-28 22:46:29
【问题描述】:

你能帮我解决一下那个代码吗,我是一个正在尝试解决它的初学者。 我正在从特定工作表(第一页)创建 PDF 文件,我想将其添加到带有抄送地址的电子邮件中。

Sub zapisz()

Dim ThisFile As String
Dim OutApp As Object
Dim OutMail As Object

ThisFile = Range("b8").Value & " " & Range("b9").Value & " " & Range("g8").Value & " " & Range("h8").Value

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    ThisFile, Quality:= _
    xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
    From:=1, To:=1, OpenAfterPublish:=False


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = ""
    .CC = "monika@xx.pl"
    .BCC = ""
    .Subject = "Oferta xxx"
    .Body = "Szanowni Państwo, w załączniku przesyłam ofertę."
    .Attachments.Add (ThisFile & "*" & ".pdf")
    .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

With Application
    .ScreenUpdating = True
    .EnableEvents = True
 End With

 End Sub`

【问题讨论】:

  • 还有什么问题?您是否遇到特定错误?

标签: vba pdf outlook


【解决方案1】:

使用后期绑定做得很好,在 StackOverflow 中提问时,这确实是一个很好的做法!一般来说,试试这样:

Sub zapisz()

        Dim ThisFile As String
        Dim OutApp As Object
        Dim OutMail As Object

        ThisFile = Range("b8") 'include the rest of your range here for the name

        ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            ThisFile, Quality:= _
            xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
            From:=1, To:=1, OpenAfterPublish:=False        

        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .To = ""
            .CC = "monika@xx.pl"
            .BCC = ""
            .Subject = "Oferta xxx"
            .Body = "Szanowni Panstwo, w zalaczniku przesylam oferte."
            .Attachments.Add (ThisWorkbook.Path & "\" & ThisFile & ".pdf")
            .Display
        End With
        'more of your code here
End Sub

确保将初始 Excel 文件保存在某个位置(您的 PC 中的任何位置都可以使用)。保存后,您可以使用ThisWorkbook.Path 添加附件。 我已经修改了ThisFile = Range("B8"),但是您可以在需要时将其修复。

您可以考虑删除On Error GoTo 0,仅当您在它之前使用诸如On Error Resume NextOn Error GoTo zapisz_Error 之类的错误捕获器时才需要它。

【讨论】:

    猜你喜欢
    • 2020-11-21
    • 1970-01-01
    • 2016-08-29
    • 2023-03-30
    • 1970-01-01
    • 2017-06-23
    • 2018-06-18
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多