【问题标题】:Using VBA how do I call up the Adobe Create PDF function使用 VBA 如何调用 Adob​​e Create PDF 功能
【发布时间】:2016-09-29 20:03:09
【问题描述】:
  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。

我该怎么做?

我正在使用 Excel 2016 和 Adob​​e Pro DC

这些是我的 adobe 参考资料

【问题讨论】:

  • Acrobat 插件是否提供 API?对象模型?可以从 VBA 以编程方式访问的 任何东西?如果没有,您可能不得不求助于 SendKeys,这是一种可怕的、可怕的做事方式。保存为 PDF 有什么问题? Adobe 插件有哪些 Excel 尚未完成的功能?
  • 如果我正常保存为 PDF,它将展平文档中的所有链接。
  • This 可能会有所帮助
  • 与@Mat'sMug 评论相关,您是否尝试添加 Adob​​e Acrobat 的参考并查看那里的可用命令? (参考资料->Adobe Acrobat)
  • 在 Excel VBA 编辑器中,转到工具->参考-> 查找类似于 acrobat 的内容。参考附件图片图片1:s20.postimg.org/3qxr9vqpp/Capture.png图片2:s20.postimg.org/iuoirq2gt/Capture.png

标签: vba excel pdf acrobat


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

请尝试以上代码

【讨论】:

  • 问题是不调用Adobe,超链接不能转成PDF
【解决方案2】:

Acrobat 参考应该可以工作
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

【讨论】:

  • 参考文档并尝试将它们与底部提供的代码结合起来“玩”,因为我没有 Acrobat,所以无法进一步编码。
【解决方案3】:
With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:="N:\JKDJKDJ", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True,  
    IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

【讨论】:

  • 值得注意的是,使用这种方法时我的链接不会变平
【解决方案4】:

您可以使用 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

【讨论】:

  • 问题是不调用Adobe,超链接不能转成PDF
  • URL 超链接对我有用。书签超链接变平。 jellz77 也使用 ExportAsFixedFormat 并且您说它没有使它们变平。如果你能把你的工作簿寄给我,我会拿很多。如果没有,您可以发布其余的代码吗?
猜你喜欢
  • 1970-01-01
  • 2018-12-06
  • 2011-09-27
  • 2020-11-14
  • 1970-01-01
  • 2014-09-29
  • 1970-01-01
  • 2012-09-06
  • 1970-01-01
相关资源
最近更新 更多