Excel VBA - unable to attach XLS file to PDF

New Here ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

I have the folowing VBA code that successfully creates two signature fields in PDF and then stops with Object Required error at Set oAttachment = oJS.ImportDataObject(Selected_File). Any ideas how to make it work?

===========================================================================================================

Sub Prepare_PDF()

On Error GoTo Err_Handler

Dim pdfPDDoc As New AcroPDDoc, oJS As Object, oFields, oAttachment As Object

Dim strFName As String

Dim oParam As Parameter

   

strFName = "C:\Main.pdf"

'------- Select XLS file to embed ----------

With Application.FileDialog(msoFileDialogFilePicker)

.AllowMultiSelect = False

.Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1

.Show

Selected_File = .SelectedItems.Item(1)

End With

   

'------- Add signature fields to PDF file----------

If pdfPDDoc.Open(strFName) Then

Set oJS = pdfPDDoc.GetJSObject

Set oFields = oJS.AddField("SignatureField1", "signature", 0, Array(200, 620, 450, 670))

Set oFields = oJS.AddField("SignatureField2", "signature", 0, Array(200, 520, 450, 570))

'------- Embed XLS in PDF file----------

Set oAttachment = oJS.ImportDataObject(Selected_File)

'------- Save PDF file------------------

strFName = Left(strFName, Len(strFName) - 4) & "-signed.pdf"

pdfPDDoc.Save 1, strFName

End If

Exit_Proc:

    Exit Sub

       

Err_Handler:

    MsgBox "In test" & vbCrLf & Err.Number & "--" & Err.Description

    Resume Exit_Proc

End Sub

TOPICS
Acrobat SDK and JavaScript

Views

375

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

You have to specify a name for the data object as the first parameter.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

I am trying Set oAttachment = oJS.ImportDataObject("Attachment", Selected_File), still generates Object Required error.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

In my experience, you may have to provide all optional parameters for some func in the JSO to work. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

Tracing the code I figured out that Selected_File was a string, not an object and now fixed it. Now I am getting Type mismatch error. Hope this is getting me closer to the answer...

Karl, in the JavaScript for Acrobat API Reference I found the following example: this.importDataObject("MyData2", "../Foo.xml"), are there any other optional parameters? Thank you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 17, 2019 Aug 17, 2019

Copy link to clipboard

Copied

LATEST

In the API reference you will also find the list of parameters. There are three. I am writing this on my phone, so it’s not as straight forward to attach a screenshot. The third parameter is cCryptFilter

However, because you got it working, that missing optional parameter was not the problem.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines