Skip to main content
Inspiring
February 12, 2026
Question

Using VBA to work with Portfolios

  • February 12, 2026
  • 2 replies
  • 150 views

I am familiar with using VBA to add data to fields of PDF Forms and to combine two PDF Files together.

I am looking to work with PDF Portfolios - specifically, I need to be able to tell if a file is a portfolio, create a portfolio from separate PDF files, and add additional files to an existing portfolio.

For determining if the file is a portfolio, the code I found online suggested this (after getting to the jso object):

        ' The key is the Doc.collection property in the Acrobat JavaScript API
' For a standard PDF, it returns a null object; for a portfolio, it returns a collection object
If Not jso.Doc.collection Is Nothing Then
IsPDFPortfolio = True
End If

The code is failing on the If statement for me with Error 438: Object does not support this property or method.

After a lot of searching I found:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsdevguide/JS_Dev_PDFCreation.html?highlight=collection

That made me think I should be using:

If Not Doc.dataObjects is Nothing Then

Or perhaps:

If Not Doc.dataObjects() is Nothing Then

But both of those give the same error.

Basically, the same question was asked here and never answered:
 

I’m not sure where to find the appropriate SDK. I think I had a copy a few years ago.



 

    2 replies

    Karl Heinz  Kremer
    Community Expert
    Community Expert
    February 16, 2026

    Hi Marshall,

     

    You should still be able to access the SDK documentation, but it’s no longer an ice PDF file as in the olden days: It’s web based: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html

     

    That was the link to the JavaScript API, which I normally reference. There is also a link to the top level page that references all the SDKs:
     

    https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/

    Inspiring
    February 16, 2026

    Minor Update - It looks like the SDK’s are now fee-based and cloud-based. Maybe 5 years ago I had a detailed PDF file with the API syntax, I can’t find it now.

    Trial and error showed me that the IF Statement should be:

    If Not jso.collection is Nothing Then.

    That returns true if I pass a portfolio file to the function. If I pass an non-portfolio file to the function, that gives me the Error 438. Apparently jso.collection doesn’t exist for a non-porfolio, it does NOT return Null as it says.

    I can errror-trap and return false if Error 438 occurs, but I’d prefer a more elegant solution.

    Inspiring
    February 16, 2026

    Making progress! So much of the info out there is just slightly incorrect …
     

    Sub createPDFPortfolio(filePath1 As String, filePath2 As String, SavePath As String)
    Dim AcroApp As Object
    Dim Doc As Object
    Dim jso As Object
    Dim collection As Object

    ' Create Acrobat application object
    Set AcroApp = CreateObject("AcroExch.App")
    Set Doc = CreateObject("AcroExch.PDDoc")

    ' AcroApp.Hide ' Optional: hide the Acrobat window
    Doc.Create ' Create a new temporary document

    ' Get the JavaScript object
    Set jso = Doc.GetJSObject

    ' Create a new portfolio (called a "collection" in Adobe parlance)
    Set collection = jso.App.newcollection()

    ' Add files to the portfolio (must use the correct path format with forward slashes)
    ' The cName is the displayed name in the portfolio, cDIpath is the file path
    If jso.importDataObject("Signoff.pdf", filePath1) = True Then
    MsgBox "File added to portfolio!"
    Else
    MsgBox "Could not add file."
    End If
    If jso.importDataObject("Signoff.pdf", filePath2) = True Then
    MsgBox "File added to portfolio!"
    Else
    MsgBox "Could not add file."
    End If

    ' Save the portfolio
    collection.SaveAs (SavePath)

    ' Clean up
    AcroApp.Exit
    Set collection = Nothing
    Set jso = Nothing
    Set Doc = Nothing
    Set AcroApp = Nothing
    End Sub

    This appears to work - I get two messages about being able to add data to the file, but when I open the file (in any PDF App), I just see a cover sheet about downloading Acrobat Reader X or above  - which I already have. Also, the file size is only 37K when the originals were 288 and 1.2 MB, which tells me it didn’t really work. Changing collection.SaveAs to Doc.SaveAs gave me an Object doesn’t support this property error.

    Sub AddFileToPDFPortfolio(portfolioPath As String, fileToAddPath As String, objectName As String)
    ' https://www.mrexcel.com/board/threads/in-excel-vba-how-do-you-export-as-pdf-and-embed-the-original-excel-file.1034503/
    ' Dim AcroApp As Acrobat.CAcroApp
    ' Dim Doc As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim collection As Object

    ' Create Acrobat application object
    Set AcroApp = CreateObject("AcroExch.App")

    ' Open the existing portfolio document
    Set Doc = CreateObject("AcroExch.PDDoc")
    If Doc.Open(portfolioPath) Then
    Set jso = Doc.GetJSObject

    ' Get the "Collection" object (the portfolio container)
    Set collection = jso.App.newcollection()

    ' Add the file to the portfolio using importDataObject
    ' The 'cName' argument is the name displayed within the portfolio
    ' The 'cDIpath' argument is the full path to the file on your local system
    ' MsgBox objectName
    ' MsgBox fileToAddPath
    If jso.importDataObject(objectName, fileToAddPath) = True Then
    MsgBox "File " & objectName & " added to portfolio successfully."

    ' The Collection object must be saved
    ' Note: The SaveAs method can be tricky with network paths; ensure correct path formatting
    collection.SaveAs portfolioPath
    Else
    MsgBox "Failed to add file to portfolio."
    End If

    ' Close the document and application
    Doc.Close
    Else
    MsgBox "Could not open the portfolio file."
    End If

    AcroApp.Exit
    Set collection = Nothing
    Set jso = Nothing
    Set Doc = Nothing
    Set AcroApp = Nothing
    End Sub

    This does the same thing - it gave me an error about saving the file b/c it was already open, but when I saved it manually, it just opens to a message to download Reader or Acrobat.

    I can save the file with a new name and use FSO to delete the original file and rename the new one, but it doesn’t do any good if the file is empty.
     

    Inspiring
    February 18, 2026

    I posted more info and asked additional questions in the Mr.Excel Thread also.

    I ended up not needing this, but this works for testing whether a file is a portfolio or not:

    Sub Usage()
    MsgBox (IsPDFPortfolio("C:\MyFile.pdf"))
    End Sub

    Public Function IsPDFPortfolio(filePath As String) As Boolean
    ' Requires Full Version of Acrobat
    ' Requires reference to Adobe Acrobat X.0 Type Library
    On Error GoTo Error_Handler
    Dim gApp, avDoc
    If Dir(filePath) = "" Then
    MsgBox "File not found: " & filePath
    Exit Function
    End If
    IsPDFPortfolio = False
    Set gApp = CreateObject("AcroExch.app")
    gApp.Hide
    gApp.show
    Set avDoc = CreateObject("AcroExch.AVDoc")
    avDoc.Open filePath, ""
    Set PDDoc = avDoc.GetPDDoc()
    Set JSO = PDDoc.GetJSObject
    If Not JSO.Collection Is Nothing Then
    IsPDFPortfolio = True
    End If

    Error_Handler_Exit:
    PDDoc.Close
    avDoc.Close (True)
    gApp.Exit
    Set gApp = Nothing
    On Error GoTo 0
    Exit Function

    Error_Handler:
    If Err = 438 Then ' Object Doesn't Support This Property or Method.
    Err.Clear
    Else
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
    "Error Number: " & Err.Number & vbCrLf & _
    "Error Source: Function IsPDFPortfolio" & vbCrLf & _
    "Error Description: " & Err.DESCRIPTION & _
    Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
    , vbOKOnly + vbCritical, "An Error has Occured!"
    End If
    Resume Error_Handler_Exit

    End Function