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

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
126
Office Version
  1. 365
Platform
  1. Windows
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:
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!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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