VBA - Excel to PDF

L

Legacy 381192

Guest
Hello, I need a master's help. I have a code to copy the data from a spreadsheet to a PDF. This is the code:

Code:
Sub CommandButton1_Click()
    Dim AcroApp As Acrobat.CAcroApp
    Dim AcroDOC As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim PDFPath, PDFOut As String
      
    Set AcroApp = CreateObject("AcroExch.App")
    AcroApp.Hide
    Set AcroDOC = CreateObject("AcroExch.PDDoc")
    PDFPath = ThisWorkbook.Path & "\" & "S-89.pdf"
    AcroDOC.Open (PDFPath)
    Set jso = AcroDOC.GetJSObject


    ' set a field text
    Dim cmp1(1 To 4) As Object


    Set cmp11 = jso.getField("Name0")
    Set cmp12 = jso.getField("Assistant0")
    Set cmp13 = jso.getField("Date0")
    Set cmp14 = jso.getField("CounselPoint0")


    Dim i As Integer
    For i = 1 To 4
    cmp1(i).Value = Cells(i, 1).Value
    Next i
       
    PDFOut = ThisWorkbook.Path & "\" & "S-89_2.pdf"
    AcroDOC.Save 1, PDFOut
    AcroDOC.Close


    AcroApp.Exit
    Set AcroApp = Nothing
    Set AcroDOC = Nothing


End Sub

In CMP (Variable).I have a list of "sequential" names, how can I create an array to help me.
Example:

For 1 to 10
Set cmp1(i).value = jso.getfield("Name" & i)
cmp1(i).Value = Cells(i, 1).Value




Currently giving this error:
Code:
cmp1(i).Value = Cells(i, 1).Value

Tnx alot.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top