Skip to main content
Inspiring
February 12, 2026
Question

Using VBA to work with Portfolios

  • February 12, 2026
  • 2 replies
  • 2 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 16, 2026

    More progress, the file in the Mr.Excel forum actually works properly, i.e.:
     

    Public Sub Attach_Workbook_to_PDF()

    Dim AcroPDDoc As Acrobat.CAcroPDDoc
    Dim JSO As Object
    Dim inputPDFfile As String, outputPDFfile As String
    Dim workbookFile As String

    'The workbook to be attached to the PDF file

    workbookFile = "C:\folder\Workbook.xlsx"

    'The PDF file to contain the workbook

    inputPDFfile = "C:\folder\PDF file.pdf"

    'File name which the PDF file will be saved as - can be same as the input PDF file or a different name

    outputPDFfile = inputPDFfile

    Set AcroPDDoc = CreateObject("AcroExch.PDDoc")

    If AcroPDDoc.Open(inputPDFfile) Then

    Set JSO = AcroPDDoc.GetJSObject

    'Attach the Excel workbook to the PDF file

    If JSO.importDataObject(Mid(workbookFile, InStrRev(workbookFile, "\") + 1), workbookFile) Then

    'Save and close the output PDF file

    AcroPDDoc.Save 1, outputPDFfile
    AcroPDDoc.Close
    MsgBox "Created " & outputPDFfile & vbNewLine & "containing " & workbookFile

    Else

    MsgBox "Unable to attach " & workbookFile & vbNewLine & " to " & inputPDFfile

    End If

    Else

    MsgBox "Unable to open " & vbNewLine & inputPDFfile

    End If

    End Sub

    That is designed for adding a .xls file to the PDF Portfolio, but it works fine for adding a PDF file also.

    Need to test if it can be used to create a new portfolio also.