VBA Acrobat Reference Disappears After Saving/Closing/Reopening Excel on CreateObject("AcroExch.PDDoc") When Merging PDFs

emreimer

New Member
Joined
Mar 29, 2016
Messages
1
I have a macro that opens and consolidates PDF files. This requires the reference "Acrobat" which is pointed to the Acrobat installation folder's file "acrobat.tlb." With Excel and VBA open, I add this reference and the code runs successfully. However, if I save and close Excel, then reopen it and look at the checked references, the "Acrobat" reference is unchecked and now the reference "Adobe Acrobat 10.0 Type Library" is checked instead. Now the code does not run through as before (an interactive window appears that says "Please wait while Windows configures Oce PRISMAaccess/prepare Core"). This happens at this line:
Set PartDocs(i) = CreateObject("AcroExch.PDDoc")
When I cancel out these multiple successive windows, the code does complete, but this will not work for my automated process.

I need help to either:
1) Make the correct reference persist after saving/closing Excel.
or
2) Suppress the interactive window that appears. Neither of these lines achieve this:
Application.ScreenUpdating = False
Application.EnableEvents = False

I read another post that said if I simply added a Private Sub Workbook_open() header/footer (with no actual code) in the workbook it would solve the reference issue, but I tried this and it did not work.

This is with Excel 2010 on Windows 7.

Thanks for your help.

Code:
'Start consolidation
    Dim a As Variant, i As Long, n As Long, ni As Long, p As String
    Dim AcroApp As New Acrobat.AcroApp, PartDocs() As Acrobat.CAcroPDDoc
     
    If Right(pathRawFiles, 1) = "\" Then p = pathRawFiles Else p = pathRawFiles & "\"
    a = Split(file515String, ",")
    ReDim PartDocs(0 To UBound(a))
     
    On Error GoTo exit_
    If Len(Dir(p & file515Consol)) Then Kill p & file515Consol
    
    For i = 0 To UBound(a)
        'Check PDF file presence
        If Dir(p & Trim(a(i))) = "" Then
            MsgBox "File not found" & vbLf & p & a(i), vbExclamation, "Canceled"
            Exit For
        End If
        'Open PDF document
        'Set PartDocs(i) = CreateObject("AcroExch.PDDoc")
        Set PartDocs(i) = New Acrobat.AcroPDDoc
        PartDocs(i).Open p & Trim(a(i))
        If i Then
             ' Merge PDF to PartDocs(0) document
            ni = PartDocs(i).GetNumPages()
            If Not PartDocs(0).InsertPages(n - 1, PartDocs(i), 0, ni, True) Then
                MsgBox "Cannot insert pages of" & vbLf & p & a(i), vbExclamation, "Canceled"
            End If
            'Calc the number of pages in the merged document
            n = n + ni
            'Release the memory
            PartDocs(i).Close
            Set PartDocs(i) = Nothing
        Else
            'Calc the number of pages in PartDocs(0) document
            n = PartDocs(0).GetNumPages()
        End If
    Next
     
    Stop
     
    If i > UBound(a) Then
        'Save the merged document to file515Consol
        If Not PartDocs(0).Save(PDSaveFull, pathSave) Then
            MsgBox "Cannot save the resulting document" & vbLf & p & file515Consol, vbExclamation, "Canceled"
        End If
    End If
     
exit_:
     
    'Inform about error/success
    If Err Then
        MsgBox Err.Description, vbCritical, "Error #" & Err.Number
    ElseIf i > UBound(a) Then
        MsgBox "The resulting file is created:" & vbLf & p & file515Consol, vbInformation, "Done"
    End If
    
    'Release the memory
    If Not PartDocs(0) Is Nothing Then PartDocs(0).Close
    Set PartDocs(0) = Nothing
     
    'Quit Acrobat application
    AcroApp.Exit
    Set AcroApp = Nothing
    'End consolidation
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top