2016-05-31 816 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

我想保留書籤超鏈接。 –