2016-05-31 469 views
5
Sheets("Key Indicators").ExportAsFixedFormat Type:=xlTypePDF, 
Filename:=ArchivePath, Quality:=xlQualityStandard, 
IncludeDocProperties:=True, IgnorePrintAreas _ 
     :=False, OpenAfterPublish:=False 

目前这就是我所拥有的。使用VBA如何调用Adobe创建PDF功能

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

AdobePDFMakerForOffice

我会怎么做呢?

我使用Excel 2016的Adobe专业DC

enter image description here 这是我的土坯引用

+2

Acrobat加载项是否提供API?一个对象模型? *通过VBA以编程方式访问的任何内容?如果不是,你可能不得不求助于* SendKeys *,这是一种可怕的,可怕的做事方式。保存为PDF有什么问题? Adobe加载项是做什么的,Excel还没有? –

+0

如果我通常将其另存为PDF,则会压平文档中的所有链接。 –

+1

[This](http://superuser.com/a/921280/165271)可能有帮助 –

回答

1

Acrobat中应参考工作
Here is the guide from Adobe
添加后,您可以使用下面的代码 提示:它可能会导致你纠正编码 - 我不太确定,因为我“盲目”编码它,因为我的电脑中没有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

+0

我收到错误“无法插入页面-1” –

+1

请参阅文档并尝试将其与底部提供的代码组合起来使用,因为我没有Acrobat,所以无法进一步编码。 – Sgdva

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

值得注意的是,当使用这种方法时,我的链接不会变平坦 – jellz77

+0

它们是工作表之间的超链接吗? –

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

请尝试上面的代码

+0

问题是,如果没有调用Adobe,超链接不会转移到PDF –

1

您可以发布任何Excel范围为使用ExportAsFixedFormat的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 
+0

问题是,如果没有调用Adobe,超链接不会转移到PDF –

+0

URL超链接适用于我。书签超链接变平。 jellz77使用ExportAsFixedFormat也表示它没有将它们弄平。如果你可以寄给我你的工作簿,我会花很多钱。如果没有,你可以发表其余的代码吗? – 2016-06-09 17:46:07

+0

我想保留书签超链接。 –