Skip to main content
stevens5219313
Participant
January 11, 2017
Answered

How to select a specific field via vbscript

I'm looking to be able to select a specific field in a PDF and set it's value, as opposed to looping through all of the fields and looking for a specific field name (in VBScript (I'm just a sys admin trying to streamline a task involving filling out many PDF documents, I'm not a developer)

In other words, I'd like to replace this (which works):

On Error Goto 0
FileNm = "C:\Temp\DOC.pdf" 
Set AVDoc = CreateObject("AcroExch.AVDoc") 
If AVDoc.Open(FileNm,"") Then
    Set pdDoc = avDoc.GetPDDoc() 
    Set PDFForm = CreateObject("AFormAut.App")
    Set x = PDFForm.Fields
    For Each myField In x
        If myField.Name = "Text100" Then myField.Value = "something interesting"
    Next
End If

with something like:

On Error Goto 0
FileNm = "C:\Temp\DOC.pdf"
Set AVDoc = CreateObject("AcroExch.AVDoc") 
If AVDoc.Open(FileNm,"") Then
    Set pdDoc = avDoc.GetPDDoc() 'actual PDF document
    Set PDFForm = CreateObject("AFormAut.App")
    Set x = PDFForm.Fields
    Set myField= x.getfieldname("Text100")  '<== this is the line I'm trying to figure out
    myField.Value = "something interesting"
End If

Can it be done?

And thanks!

This topic is closed to new replies. Start a new post to keep the conversation going.
Karl Heinz  Kremer
Karl Heinz KremerCorrect answer
Community Expert
January 11, 2017

Take a look at the Fields.Item property:

Acrobat DC SDK Documentation

You'll find sample code in the SDK documentation that returns one field that you specify via the field name. 

2 replies

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
January 11, 2017

Take a look at the Fields.Item property:

Acrobat DC SDK Documentation

You'll find sample code in the SDK documentation that returns one field that you specify via the field name. 

Translate
stevens5219313
Participant
January 11, 2017

Many thanks!

Translate