Share via

Save adobe pdf file as pdf

Anonymous
2019-11-17T20:33:23+00:00

Hello, I am trying to automate an adobe pdf population via VBA editor.

I managed to populate the fields so far but not sure how to save the file as pdf.

Thanks for your help!

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

Dim AcrobatApplication As Acrobat.CAcroApp

Dim AcrobatDocument As Acrobat.CAcroAVDoc

Dim Fcount As Long

Dim sFieldName As String

Set AcrobatApplication = CreateObject("AcroExch.App")

Set AcrobatDocument = CreateObject("AcroExch.AVDoc")

If AcrobatDocument.Open("C:\Users\ilotvin001\Desktop\VBA Tests\Excel to PDF\1test.pdf", "") Then

AcrobatApplication.Show

Set Acroform = CreateObject("AFormAut.App")

Set Fields = Acroform.Fields

Fcount = Fields.Count

Fields("A Identifying number").Value = "Testing 1"

Fields("City or town state and ZIP code").Value = "Testing2"

Fields("Name of person filing this return").Value = "Testing3"

Else

MsgBox "Check"

End If

AcrobatApplication.Exit

Set AcrobatApplication = Nothing

Set Field = Nothing

Set AcrobatDocument = Nothing

Set Acroform = Nothing

Set Fields = Nothing

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

8 answers

Sort by: Most helpful
  1. Anonymous
    2019-11-21T19:17:55+00:00

    You are almost there.

    The statement:

    Dim PdfDoc As Acrobat.CAcroPDDoc

    is correct

    The second statement should be something to the effect:

    Set PdfDoc = AcrobatDocument.GetPDDoc()

    After you have made your edits to the contents of the fields, use the Save method of the PDDoc object.

    PdfDoc.Save PDSaveFull, " the full path for the file "

    I Hope that makes sense and helps you.

    Bill

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-11-21T18:47:24+00:00

    Hello and thank you for your help.

    I'm slightly struggling to follow you instructions.

    Would you be able to help me out to add the required code to print the file into pdf and close the file?

    Would really appreciate it!

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

    Dim AcrobatApplication As Acrobat.CAcroApp

    Dim AcrobatDocument As Acrobat.CAcroAVDoc

    Dim PdfDoc As Acrobat.CAcroPDDoc '#1

    Dim WasSaved As Variant

    Dim Fcount As Long

    Dim sFieldName As String

    Set AcrobatApplication = CreateObject("AcroExch.App")

    Set AcrobatDocument = CreateObject("AcroExch.AVDoc")

    Set PdfDoc = CreateObject("AcrExch.PDDoc") '#2

    If AcrobatDocument.Open("Path\FileName.pdf", "") Then

    AcrobatApplication.Show

    Set Acroform = CreateObject("AFormAut.App")

    Set Fields = Acroform.Fields

    Fcount = Fields.Count

    Fields("A Identifying number").Value = Sheet1.Range("F5").Value

    Fields("City or town state and ZIP code").Value = Sheet1.Range("I5").Value & " " & Sheet1.Range("J5").Value

    Fields("Name of person filing this return").Value = Sheet1.Range("E5").Value

    Else

    MsgBox "Check"

    End If

    AcrobatApplication.Exit

    Set AcrobatApplication = Nothing

    Set Field = Nothing

    Set AcrobatDocument = Nothing

    Set Acroform = Nothing

    Set Fields = Nothing

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2019-11-18T14:51:48+00:00

    The Acrobat SDK Documentation describes the different Objects you are using.

    You have referenced

    App : the application itself

    AVDoc : the document as seen in the user interface

    There is another one you will need:

    PDDoc : the underlying PDF representation of the document

    After dimensioning the PDDoc object, you can use the GetPDDoc method of the AVDoc object to set it.

    From there you can use the Save method of the PDDoc object.

    You can refer to the documentation that was part of the Acrobat SDK.

    I hope that helps

    Bill

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2019-11-21T22:07:43+00:00

    Well.

    It may be trying to return a Boolean.

    let's try:

    Dim x as Boolean

    x = PdfDoc.Save PDSaveFull, "C:\Users\ilot\Desktop\VBA Tests\Excel to PDF - Not perfect_Need to fix"

    here is a link to the Adobe Reference:

    https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2019-11-21T21:32:25+00:00

    Bill, Thank you so much for your help.

    I tried to add the missing statements, however I'm getting an error message:

    Run-Time error 91':

    Object variable or With block variable not set

    Error is pointing to the PDFDOC.save statement.

    Can you please let me know if you know what is wrong with what I did?

    Is it related to missing brackets by any chance

    Thanks again.

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

    Sub WriteToAdobeFields()

    Dim AcrobatApplication As Acrobat.CAcroApp

    Dim AcrobatDocument As Acrobat.CAcroAVDoc

    '==============

    Dim PdfDoc As Acrobat.CAcroPDDoc

    '===============

    Dim WasSaved As Variant

    Dim Fcount As Long

    Dim sFieldName As String

    Set AcrobatApplication = CreateObject("AcroExch.App")

    Set AcrobatDocument = CreateObject("AcroExch.AVDoc")

    '===============

    Set PdfDoc = AcrobatDocument.GetPDDoc()

    '===============

    If AcrobatDocument.Open("C:\Users\ilot\Desktop\VBA Tests\Excel to PDF - Not perfect_Need to fix\1test copy from PDF.pdf", "") Then

    AcrobatApplication.Show

    Set Acroform = CreateObject("AFormAut.App")

    Set Fields = Acroform.Fields

    'Set pdfDoc = avdoc.GetPDDoc

    Fcount = Fields.Count

    Fields("A Identifying number").Value = Sheet1.Range("F5").Value

    Fields("City or town state and ZIP code").Value = Sheet1.Range("I5").Value & " " & Sheet1.Range("J5").Value

    Fields("Name of person filing this return").Value = Sheet1.Range("E5").Value

    PdfDoc.Save PDSaveFull, "C:\Users\ilot\Desktop\VBA Tests\Excel to PDF - Not perfect_Need to fix"

    Else

    MsgBox "Check"

    End If

    AcrobatApplication.Exit

    Set AcrobatApplication = Nothing

    Set Field = Nothing

    Set AcrobatDocument = Nothing

    Set Acroform = Nothing

    Set Fields = Nothing

    End Sub

    Was this answer helpful?

    0 comments No comments