3

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

TylerH
  • 20,799
  • 66
  • 75
  • 101
excelguy
  • 1,574
  • 6
  • 33
  • 67
  • 1
    It looks like the missing type library isn't included with Reader. See https://stackoverflow.com/a/30312733/1352761 – studog Nov 18 '18 at 03:17
  • Similar to this question: https://stackoverflow.com/questions/48028987/vba-late-binding-avaoid-reference-of-acrobat-type-library – HackSlash Nov 20 '18 at 19:52
  • ` 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 Nov 21 '18 at 21:27
  • 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 Nov 23 '18 at 09:38
  • You need to have the same version of Acrobat Pro installed on the second computer for your code to work. – RIBH Nov 24 '18 at 19:53
  • Please do not vandalize your posts. Keep in mind that, once posted, content on this site is licensed under [CC By-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/). – TylerH Feb 11 '19 at 19:33

1 Answers1

1

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

HackSlash
  • 4,944
  • 2
  • 18
  • 44
  • Yes, but regardless of binding method, to create object of certain type this type must be registered. When this type is not registered (no entry in registry) then it can't be created. That is the same as when I would write e.g. `Set mySuperMonkey = CreateObject("MonkeyLibrary.SuperMonkeyClass")`. This will not work until I register this library `MonkeyLibrary` which has to contain this class `SuperMonkeyClass` on my computer. – Daniel Dušek Nov 23 '18 at 09:43
  • Correct. You need to have a library to call upon. The late binding allows it to find the installed version instead of hard-coding a link to a version that may not exist. It's more flexible across computers but you still need A version of the library installed. – HackSlash Nov 26 '18 at 16:05