# Using VBA to read PDFs - ActiveX component can't create object



## rachel06 (Nov 1, 2022)

Hello,

I found an old macro at work we used to use to read PDFs for certain phrases and I know it's worked in the past. Today, I'm getting an error message:

Error:
Run-Time Error 429
ActiveX component can't create object

Here is the code:

```
Option Base 1
Dim PhraseLabel(25), PhraseText(25) As String
Sub FindPDFtextB()
'
' Opens and searches a PDF file for specified text
'
Dim TargetFolder, PDFname, PDFpath As String ' Path to files to be searched
Dim foundText As Long ' Return value from FindText method
Dim iFiles, numPhr, i As Integer
'Dim TxtB As Range

' Get number of text clauses to search for
Worksheets("Enter_Text").Activate
Range("A6").Select
Selection.End(xlDown).Select
numPhr = ActiveCell.Row - Range("TextLabel").Row

' Read text phrases into array

For i = 1 To numPhr
PhraseLabel(i) = Worksheets("Enter_Text").Range("TextLabel").Offset(i, 0).Value
PhraseText(i) = Worksheets("Enter_Text").Range("TextList").Offset(i, 0).Value
Next i

' Output goes on the Analysis worksheet
Worksheets("Analysis").Activate

Set TxtB = Worksheets("Analysis").Range("TextCheck")
For i = 1 To numPhr
TxtB.Offset(0, i - 1).Select
With Selection
.Value = PhraseLabel(i)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 45
End With
Next i


' Set file counter
iFiles = 1

' Get folder path from worksheet
TargetFolder = Worksheets("Enter_Text").Range("FolderToTestB")
If Right(TargetFolder, 1) <> "\" Then TargetFolder = TargetFolder & "\"

' Set target folder objects
Set tgtObject = New Scripting.FileSystemObject
Set tgtSource = tgtObject.GetFolder(TargetFolder)

' On Error Resume Next
Application.DisplayAlerts = False
For Each myFile In tgtSource.Files

' Initialize Acrobat by creating App object
Set tgtApp = CreateObject("AcroExch.App", "")
' tgtApp.Hide
Set tgtAvDoc = CreateObject("AcroExch.AVDoc")

PDFname = myFile.Name
PDFpath = TargetFolder & PDFname
Range("FileNameB").Offset(iFiles, 0).Value = PDFname

' open the PDF
If tgtAvDoc.Open(PDFpath, "") Then

For i = 1 To numPhr
foundText = tgtAvDoc.FindText(PhraseText(i), caseSensitive, WholeWords, bReset) 'Returns -1 if found, 0 otherwise
If foundText = -1 Then
Range("TextCheck").Offset(iFiles, i - 1).Value = "X"
Else
Range("TextCheck").Offset(iFiles, i - 1).Value = ""
End If

Next i

tgtApp.getActiveDoc.Close True
Set tgtApp = Nothing

Else ' if failed, show error message
Resp = MsgBox("Cannot open " & PDFpath, vbOKOnly)

End If

iFiles = iFiles + 1

Next

End Sub
```

The part that is highlighted when  I click to debug is this: 
Set tgtApp = CreateObject("AcroExch.App", "")

It looks like to me that maybe this is referencing a version of Acrobat I don't have? Is there something else I can put in the place of AcroExch.App? Any suggestions are super appreciated!


----------



## Tayl4n (Wednesday at 6:43 AM)

As far as I know you need to use Adobe Standard or Pro then you can check your referances. After that you should add adobe libraries


----------

