Skip to main content
Participant
Jan 29, 2024 9:05 PM UTC
Question

PDF tags automation thru VBA

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

Thom Parker
Community Expert
Community Expert
Jan 29, 2024 9:16 PM UTC

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. 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Jan 29, 2024 9:31 PM UTC

Thanks Thom.

Translate