• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2430
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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