我可以在安装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")
现在在新行上出现错误,
答案 0 :(得分:1)
您当前正在将后期绑定与早期绑定混合在一起。为了使您的代码在计算机之间可移植,请始终使用后期绑定。这样,计算机就可以在运行时查找该库,而不必在运行代码之前在每台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