• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2543
  • Last Modified:

Simple Excel VBA to open Acrobat file crashes Excel

This crashes my Excel on the OPEN command.  I have the Reference to Adobe 9.0 Type Library.

Any thoughts?

Dave

Sub Open_PDF()

Dim AcroApp As Acrobat.CAcroApp

Dim PDDoc As Acrobat.CAcroPDDoc


Set AcroApp = CreateObject("AcroExch.App")

Set PDDoc = CreateObject("AcroExch.PDDoc")


If PDDoc.Open("C:\TEST.PDF") Then '<-- this command crashes Excel

        AcroApp.Show

        Set avDoc = PDDoc.OpenAVDoc("")

Else

        MsgBox "Unable to open the PDF-file", vbInformation

End If


Set avDoc = Nothing

Set PDDoc = Nothing

Set AcroApp = Nothing

End Sub
0
dlmille
Asked:
dlmille
  • 6
  • 2
1 Solution
 
SiddharthRoutCommented:
Please change the declaration from

Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc

to

Dim AcroApp As Object
Dim PDDoc As Object

Also check this link (ID : 35003475)

Sid
0
 
SiddharthRoutCommented:
TRIED and TESTED

To Use Early Binding, Please use this code

Sub Sample()
    Dim AcroApp As Acrobat.AcroApp
    
    Dim AVDoc1 As Acrobat.AcroAVDoc
    Dim PDDoc1 As Acrobat.AcroPDDoc
    
    Dim AVDoc2 As Acrobat.AcroAVDoc
    Dim PDDoc2 As Acrobat.AcroPDDoc
    
    Set AcroApp = New AcroApp
    
    Set AVDoc1 = New AcroAVDoc
    Set AVDoc2 = New AcroAVDoc
    
    ret1 = AVDoc1.Open("C:\1.pdf", "")
    ret2 = AVDoc2.Open("C:\2.pdf", "")
    
    If ret1 = True And ret2 = True Then
        Set PDDoc1 = AVDoc1.GetPDDoc
        '~~> Code here to interact with pdf1
        PDDoc1.Save 1, "C:\3.pdf"
        
        Set PDDoc2 = AVDoc2.GetPDDoc
        '~~> Code here to interact with pdf2
        PDDoc2.Save 1, "C:\4.pdf"
        
        PDDoc1.Close
        AVDoc1.Close (True)
        
        PDDoc2.Close
        AVDoc2.Close (True)
        
        AcroApp.Exit
        MsgBox "Done"
    End If
End Sub

Open in new window


Also if you are on the Office pc and you don't have admin rights then creating an instance of Acrobat will crash your Excel. This used to happen with me as well.

Sid
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
dlmilleAuthor Commented:
Early binding crashes.

The object approach works.

Why does early binding crash on every machine I attempt it on?

Dave
0
 
SiddharthRoutCommented:
It doesn't crash for me.

Sid
0
 
dlmilleAuthor Commented:
ok - would you run all my programs that need this form me and send me the output?

lol :)

This has been tried on several setups, so obviously its a setup issue.  What could cause the crashing?

Dave
0
 
SiddharthRoutCommented:
Sure not a problem.

Sid
0
 
SiddharthRoutCommented:
>>>This has been tried on several setups, so obviously its a setup issue.  What could cause the crashing?

Like I mentioned earlier Dave in ID: 35480082

>>>Also if you are on the Office pc and you don't have admin rights then creating an instance of Acrobat will crash your Excel. This used to happen with me as well

You need full control over system32 folder else you will get this error.

Sid
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now