Skip to main content
stevens5219313
Participant
January 11, 2017
Answered

How to select a specific field via vbscript

  • January 11, 2017
  • 1 reply
  • 2469 views

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):

OnErrorGoto0
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
    ForEach myFieldIn x
        If myField.Name = "Text100"Then myField.Value = "something interesting"
    Next
EndIf

with something like:

OnErrorGoto0
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
    SetmyField= x.getfieldname("Text100")  '<== this is the line I'm trying to figure out
    myField.Value = "something interesting"
EndIf

Can it be done?

And thanks!

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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. 

1 reply

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. 

stevens5219313
Participant
January 11, 2017

Many thanks!