'jso.numfields not returning anything within Excel VBA while connecting to PDF file
So I am trying to write a VBA Macro in Excel that will loop through all 400+ .pdf files I have in a folder, extract pertinent data from them, and store that data in an Excel spreadsheet. However I am not sure that my .pdf files are even being opened. My file path is good, but when I try to detect any fields in the .pdf file using .numfields, it returns 0. I've checked Adobe Acrobat in my References tool, are there any 'things' I need to set up for JS Objects to work in Excel VBA ?
Here is my code so far:
Private Sub CoH_Water_Invoice()
'Declare the File Path
Dim path As String: path = "K:\Administration\Utilities\FY22\"
Dim file As String: file = Dir(path & "*.pdf")
'Set up Variables/Acrobat Objects
Dim AcroApp As Acrobat.CAcroApp
Dim theForm As Acrobat.CAcroPDDoc
Dim jso As Object
Set AcroApp = CreateObject("AcroExch.App")
Set theForm = CreateObject("AcroExch.PDDoc")
theForm.Open(path & file)
Set jso = theForm.GetJSObject
'Check for fields
If jso.numfields > 0 Then
Debug.Print("Fields detected")
Else
Debug.Print("No Fields detected")
End If
theForm.Close
AcroApp.Exit
Set AcroApp = Nothing
Set theForm = Nothing
End Sub
In the "Immediates" window, I always get "No Fields detected", so it is not picking up any fields in the JS Object. Any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|