Using VBA how do I call up the Adobe Create PDF function
Asked Answered
B

4

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

Currently this is what I have.

I understand how to ExportAsFixedFormat PDF but what I need to know how to do is to access the Create PDF function under Acrobat (As show in the picture below) using VBA. If I do ExportAsFixedFormat the links get flattened. Acrobat "Create PDF" would allow me to convert an Excel to PDF with hyperlinks included.

AdobePDFMakerForOffice

How would I do that?

I am using Excel 2016 and Adobe Pro DC

enter image description here These are my adobe references

Beccafico answered 31/5, 2016 at 17:20 Comment(7)
Does the Acrobat add-in provide an API? an object model? anything that's programmatically accessible from VBA? If not, you might have to resort to SendKeys, which is a horrible, horrible way of doing things. What's wrong with saving as PDF? What does the Adobe add-in do that Excel doesn't already?Tenement
If I save as PDF normally it will flatten all of the links in the document.Beccafico
This might helpTenement
Related to @Mat'sMug comment, have you tried to add the reference for Adobe Acrobat and see the available commands there? (References->Adobe Acrobat)Armandinaarmando
How would I do that?Beccafico
In Excel VBA Editor, go to Tools->References-> Look for something that resembles acrobat. See attached images for reference Image1: s20.postimg.org/3qxr9vqpp/Capture.png Image2: s20.postimg.org/iuoirq2gt/Capture.pngArmandinaarmando
It is true that the builtIn PDF Publishing only retains Web URLs, Hyperlinks that goes to another Range in the workbook are removed.Mangan
A
1

Acrobat Reference should work
Here is the guide from Adobe
Once added, you may use the following code Tip: It may lead you to correct coding -I'm not quite sure since I coded it "blindly" because I don't have Acrobat in my PC-. Debug step by step to see what's doing.

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

Following pages may provide better assistance: Link1, Link2

Armandinaarmando answered 3/6, 2016 at 18:2 Comment(1)
Refer to the documentation and try to "play" combining them with the codes provided at the bottom, can't code further since I don't have Acrobat.Armandinaarmando
N
3
Sub PDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\PCNAME\Documents\Book1.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    True
End Sub

Please try the above codes

Novella answered 4/6, 2016 at 6:31 Comment(1)
The problem is that without calling up Adobe, the hyperlinks do not transfer to PDFBeccafico
W
1
With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:="N:\JKDJKDJ", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True,  
    IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Withy answered 3/6, 2016 at 14:46 Comment(1)
worth noting my links don't get flattened when using this approachWithy
A
1

Acrobat Reference should work
Here is the guide from Adobe
Once added, you may use the following code Tip: It may lead you to correct coding -I'm not quite sure since I coded it "blindly" because I don't have Acrobat in my PC-. Debug step by step to see what's doing.

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

Following pages may provide better assistance: Link1, Link2

Armandinaarmando answered 3/6, 2016 at 18:2 Comment(1)
Refer to the documentation and try to "play" combining them with the codes provided at the bottom, can't code further since I don't have Acrobat.Armandinaarmando
E
1

You can publish any Excel Range as a PDF using ExportAsFixedFormat. There is no need to set a refernce to 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
Erfurt answered 9/6, 2016 at 2:29 Comment(2)
The problem is that without calling up Adobe, the hyperlinks do not transfer to PDFBeccafico
URL hyperlinks work for me. Bookmark hyperlinks get flattened. jellz77 uses ExportAsFixedFormat also an you said that it didn't flatten them. If you can send me your workbook I'll take a lot. If not can you post the rest if your code?Erfurt

© 2022 - 2024 — McMap. All rights reserved.