3
votes

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

enter image description here

So then I uncheck "MISSING: Adobe Acrobat 10.0 Type Library" which dissolves this error,

enter image description here

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,

enter image description here

enter image description here

1
It looks like the missing type library isn't included with Reader. See stackoverflow.com/a/30312733/1352761 - studog
` I have another computer without ...` that is the problem because AcroExch.PDDoc is part of Acrobat (but is not available in Reader). The classes you reference and try to create object of it are located in that files of Acrobat. So it is not problem of binding type, it doesn't work because such types are not registered on that another computer. So if the question is how to solve the errors: install Adobe Reader on that computer as well. - Daniel Dušek
Your VBA project contains reference to Adobe Acrobat Type Lib. This reference was included on the computer where the Adobe Acrobat is installed. When you move the excel file with this VBA project to that another computer, where the Adobe Acrobat is not installed, then this reference is, well MISSING, which is expected. You simply can't create object from type, which is not registered on that another computer, that's it. - Daniel Dušek
You need to have the same version of Acrobat Pro installed on the second computer for your code to work. - RIBH

1 Answers

1
votes

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