使用VBA如何调用Adobe Create PDF功能

时间:2016-05-31 17:20:16

标签: excel vba excel-vba pdf acrobat

  Sheets("Key Indicators").ExportAsFixedFormat Type:=xlTypePDF,
 Filename:=ArchivePath, Quality:=xlQualityStandard,
 IncludeDocProperties:=True, IgnorePrintAreas _
         :=False, OpenAfterPublish:=False

目前这就是我所拥有的。

我理解如何ExportAsFixedFormat PDF,但我需要知道的是使用VBA访问Acrobat下的Create PDF功能(如下图所示)。如果我执行ExportAsFixedFormat,链接会变平。 Acrobat"创建PDF"允许我将Excel转换为包含超链接的PDF。

AdobePDFMakerForOffice

我该怎么做?

我正在使用Excel 2016和Adobe Pro DC

enter image description here 这些是我的adobe参考

4 个答案:

答案 0 :(得分:3)

Sub PDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\PCNAME\Documents\Book1.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    True
End Sub

请尝试以上代码

答案 1 :(得分:1)

With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:="N:\JKDJKDJ", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True,  
    IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

答案 2 :(得分:1)

Acrobat Reference应该工作
Here is the guide from Adobe
添加后,您可以使用以下代码 提示:它可能会导致您纠正编码 - 我不太确定,因为我“盲目地”编码它,因为我的PC中没有Acrobat。一步一步调试,看看正在做什么。

Sub ExportWithAcrobat()
Dim AcroApp As Acrobat.CAcroApp 'I'm not quite sure it's needed since we are creating the doc directly
Dim AcrobatDoc As Acrobat.CAcroPDDoc
Dim numPages As Long
Dim WorkSheetToPDF As Worksheet
Const SaveFilePath = "C:\temp\MergedFile.pdf"
    Set AcroApp = CreateObject("AcroExch.App") 'I'm not quite sure it's needed since we are creating the doc directly
    Set AcrobatDoc = CreateObject("AcroExch.PDDoc")
    'it's going to be 0 at first since we just created
    numPages = AcrobatDoc.GetNumPages
    For Each WorkSheetToPDF In ActiveWorkbook.Worksheets
    If AcrobatDoc.InsertPages(numPages - 1, WorkSheetToPDF, 0, AcrobatDoc.GetNumPages(), True) = False Then 'you should be available to work with the code to see how to insert the sheets that you want in the created object ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False
    MsgBox "Cannot insert pages" & numPages
    Else ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False
    numPages = numPages + 1
    End If ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False
    Next WorkSheetToPDF
    If AcrobatDoc.Save(PDSaveFull, SaveFilePath) = False Then ' 2. If Part1Document.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False
    MsgBox "Cannot save the modified document"
    End If ' 2. If Part1Document.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False
End Sub

以下页面可能会提供更好的帮助:Link1Link2

答案 3 :(得分:1)

您可以使用ExportAsFixedFormat将任何Excel范围发布为PDF。无需设置对Acrobat的引用。

' Usage:
' PublishRangePDF(Thisworkbook, fileName) : Will Publish the entire Workbook
' PublishRangePDF(AvtiveSheet, fileName) : Will Publish all selected worksheets
' PublishRangePDF(Range("A1:H100"), fileName) : Will Publish Range("A1:H100")


Sub PublishRangePDF(RangeObject As Object, fileName As String, Optional OpenAfterPublish As Boolean = False)
    On Error Resume Next
    RangeObject.ExportAsFixedFormat Type:=xlTypePDF, fileName:=fileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=OpenAfterPublish
    On Error GoTo 0
End Sub