我可以在安装Acrobat Reader 2017以及Adobe Acrobat XI Pro和Distiller XI的情况下运行以下代码。
我有一台没有XI Pro或Distiller的计算机。
打开Excel工作表时出现的第一个问题
隐藏模块中的编译错误:xxxxx
第二个问题是我有参考资料
MISSING:Adobe Acrobat 10.0类型库
我取消选中它,然后再次运行,然后在Set acroDoc = New AcroPDDoc
上出现错误
我注意到在我的工作Excel中有“ ACROBAT”功能区,而在我没有工作的Excel中没有。
Dim acroExchangeApp As Object
Set app = CreateObject("Acroexch.app")
Dim filePaths As Collection 'Paths for PDFS to append
Set filePaths = New Collection
Dim fileRows As Collection 'Row numbers PDFs to append
Set fileRows = New Collection
Dim sourceDoc As Object
Dim primaryDoc As Object ' PrimaryDoc is what we append too
Dim insertPoint As Long ' PDFs will be appended after this page in the primary Doc
Dim startPage As Long ' First desired page of appended PDF
Dim endPage As Long ' Last desired page of appended PDF
Dim colIndex As Long '
Dim numPages As Long
Dim acroDoc As Object
Set acroDoc = New AcroPDDoc
Set primaryDoc = CreateObject("AcroExch.PDDoc")
OK = primaryDoc.Open(filePaths(1))
Debug.Print "PRIMARY DOC OPENED & PDDOC SET: " & OK
For colIndex = 2 To filePaths.count
query_start_time = time()
start_memory = GetWorkingMemoryUsage
numPages = primaryDoc.GetNumPages() - 1
Set sourceDoc = CreateObject("AcroExch.PDDoc")
OK = sourceDoc.Open(filePaths(colIndex))
Debug.Print "(" & colIndex & ") SOURCE DOC OPENED & PDDOC SET: " & OK
numberOfPagesToInsert = sourceDoc.GetNumPages
'inserts pages
acroDoc.Open source_file_name
insertPoint = acroDoc.GetNumPages - 1
If endPage > 1 Then
OK = primaryDoc.InsertPages(insertPoint, sourceDoc, startPage, endPage - startPage, False)
Debug.Print "(" & colIndex & ") " & endPage - startPage & " PAGES INSERTED SUCCESSFULLY: " & OK
Else
OK = primaryDoc.InsertPages(insertPoint, sourceDoc, startPage, endPage - startPage + 1, False)
Debug.Print "(" & colIndex & ") " & endPage - startPage + 1 & " PAGES INSERTED SUCCESSFULLY: " & OK
End If
Set sourceDoc = Nothing
Next colIndex
OK = primaryDoc.Save(PDSaveFull, filePaths(1))
Debug.Print "PRIMARYDOC SAVED PROPERLY: " & OK
Set primaryDoc = Nothing
app.Exit
Set app = Nothing
最新变化:
首先我得到
编译错误,无法找到项目或库
因此,我取消选中“ MISSING:Adobe Acrobat 10.0类型库”,此错误已解决,
在执行此更改后,现在出现以下错误:
Set acroDoc = New AcroPDDoc
至Set acroDoc = CreateObject("AcroExch.PDDoc")
现在像这样在新行上出现错误,
最佳答案
您当前正在混合后期绑定和早期绑定。为了使您的代码在计算机之间可移植,请始终使用后期绑定。这使计算机可以在运行时查找库,而不是在运行代码之前在每个PC上手动硬链接到文件。
更改此:
Set acroDoc = New AcroPDDoc
对此:
Set acroDoc = CreateObject("AcroExch.PDDoc")
读这个:
http://www.needforexcel.com/single-post/2015/10/09/Difference-Between-Early-Binding-Late-Binding