Reputation: 1624
I am able to run the following code where I have Acrobat Reader 2017 installed as well as Adobe Acrobat XI Pro and Distiller XI.
I have another computer without XI Pro or Distiller.
First issue when I open my Excel sheet I get
Compile Error in hidden module: xxxxx
Second issue is in references I have
MISSING: Adobe Acrobat 10.0 Type Library
I uncheck it and run again, then I get errors on Set acroDoc = New AcroPDDoc
I note that I have the "ACROBAT" Ribbon in my working Excel, in my non-working Excel I do not.
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
Latest change:
First I get
Compile error, Cant find project or library
So then I uncheck "MISSING: Adobe Acrobat 10.0 Type Library" which dissolves this error,
Now get the following error, after I did this change:
Set acroDoc = New AcroPDDoc
to Set acroDoc = CreateObject("AcroExch.PDDoc")
and now getting an error on the new line like so,
Upvotes: 3
Views: 8293
Reputation: 5803
You are currently mixing late binding an early binding. To make your code portable between computers, always use late binding. This allows the computer to find the library at runtime instead of hard linking to a file manually on each PC before you run the code.
CHANGE THIS:
Set acroDoc = New AcroPDDoc
TO THIS:
Set acroDoc = CreateObject("AcroExch.PDDoc")
READ THIS: http://www.needforexcel.com/single-post/2015/10/09/Difference-Between-Early-Binding-Late-Binding
Upvotes: 1