Skip to main content
Participant
January 29, 2024
Question

PDF tags automation thru VBA

  • January 29, 2024
  • 1 reply
  • 623 views

Hi guys, need your help. I am automating PDF and need to automate tags change/update.

In below code, there is no error encountered and the new PDF saved without issue

The problem is, the new tag is not applied in the new PDF document

Please give me advise how can I do it?

Thank you in advance

Public Sub renameTag()
    Dim jsObject As Object
    Dim objField As Object
    Dim result As Boolean
    Dim oneCell As Range
    Dim testField

    Set jsObject = pdfDoc.GetJSObject
    
    For Each oneCell In wsTagReplace.Range("tblTagsReplace[Rename?]")
        If oneCell.Value = 1 Then 'need to change/update tags
            Set objField = jsObject.getField(currentTag)
            objField.Name = newTag
        End If
    Next oneCell
    
    result = pdfDoc.Save(PDSaveFull, Replace(fileName, ".pdf", "_new.pdf"))
    Set objField = Nothing
    Set jsObject = Nothing
End Sub
This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 29, 2024

So your code is attempting to replace field names, not tags. In the context of PDF, "Tags" have a specific meaning, and this is not it. 

 

But anyway, you can't change a field's name.  What you can do is delete a field and recreate it with the new name. 

I'd suggest writing a folder level JS function for this and then calling it from the VBA script.  This will give you a much better way to develop and test the functionality. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
January 29, 2024

Thanks Thom.