PDA

View Full Version : ActiveX component can't create object



xxsomethingx
11-24-2010, 01:42 PM
Hello,

I'm trying to create a macro to read PDF's from a file but I cannot seem to figure out why it's giving me this error. I work at a corporation where security is overly-done(access-wise) so i was thinking that would be the reason why this is giving me this error.

What can anyone tell me about this error? Will I not be able to create this macro due to security on the computers here? Or am I just not instantiating correctly?


Sub test()
Dim AcroApp As CAcroApp
Dim AcroAVDoc As CAcroAVDoc
Dim AcroPDDoc As CAcroPDDoc
Dim AcroHiliteList As CAcroHiliteList
Dim AcroTextSelect As CAcroPDTextSelect
Dim PageNumber, PageContent, Content, i, j
**This is where it's erroring out**Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open("I:\DOC001.pdf", vbNull) <> True Then
Exit Sub
End If
Set AcroAVDoc = AcroApp.GetActiveDoc
Set AcroPDDoc = AcroAVDoc.GetPDDoc
For i = 0 To AcroPDDoc.GetNumPages - 1
Set PageNumber = AcroPDDoc.AcquirePage(i)
Set PageContent = CreateObject("AcroExch.HiliteList")
If PageContent.Add(0, 9000) <> True Then
Exit Sub
End If
Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
For j = 0 To AcroTextSelect.GetNumText - 1
Content = Content & AcroTextSelect.GetText(j)
Next j
Next i

AcroAVDoc.Close True
AcroApp.Exit
Set AcroDoc = Nothing
Set AcroApp = Nothing
End Sub

fumei
11-24-2010, 03:12 PM
Is the reference to the library checked?

xxsomethingx
11-24-2010, 04:09 PM
The current references I have set are:
Visual Basic For Applications
Microsoft Word 11.0 Object Library
OLE Automation
Normal
Microsoft Office 11.0 Object Library
Adobe Acrobat 9.0 type Library

Is there one I'm missing? I'm still new to this so I may be missing an obvious one.

fumei
11-24-2010, 04:30 PM
I do not know. Is "AcroExch.App" what comes from the Acrobat type library?

xxsomethingx
11-24-2010, 04:43 PM
Yes, I am trying to instantiate the object in order to use it. But that's where it's giving me an error. i cannot instantiate ANY objects, be it acrobat or not. Any ideas?

macropod
11-24-2010, 09:43 PM
Hi xxsomethingx,

There may be a fault in the way Acrobat is registered on your system. As a (possible) workaround, try starting Acrobat before running the macro. For example:
Sub Test()
Dim AcroApp As CAcroApp
Dim AcroAVDoc As CAcroAVDoc
Dim AcroPDDoc As CAcroPDDoc
Dim AcroHiliteList As CAcroHiliteList
Dim AcroTextSelect As CAcroPDTextSelect
Dim PageNumber, PageContent, Content, i, j, bTask As Boolean
bTask = True
If Tasks.Exists(Name:="Adobe Acrobat Professional") = False Then
bTask = False
Shell "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe", vbMinimizedFocus
End If
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open("I:\DOC001.pdf", vbNull) <> True Then
Exit Sub
End If
Set AcroAVDoc = AcroApp.GetActiveDoc
Set AcroPDDoc = AcroAVDoc.GetPDDoc
For i = 0 To AcroPDDoc.GetNumPages - 1
Set PageNumber = AcroPDDoc.AcquirePage(i)
Set PageContent = CreateObject("AcroExch.HiliteList")
If PageContent.Add(0, 9000) <> True Then
Exit Sub
End If
Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
For j = 0 To AcroTextSelect.GetNumText - 1
Content = Content & AcroTextSelect.GetText(j)
Next j
Next i
AcroAVDoc.Close True
AcroApp.Exit
If bTask = False Then Tasks.Item("Adobe Acrobat Professional").Close
Set AcroAVDoc = Nothing
Set AcroApp = Nothing
End Sub

PS: You apparently don't have 'Option Explicit' set, since 'AcroAVDoc' referred to in 'Set AcroDoc = Nothing' is your code doesn't refer to a defined variable.