I want to change the Acrobat PDF app to Kofax Power PDF, along with the APIs for this Macro

fR05t1

New Member
Joined
Jun 30, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Function MergeThePDFs(ByRef strMergeNames() As String, strPath As String, strFInalOutputDoc As String, blnKillIndFiles As Boolean) As Boolean
Dim acroOrigPdfDoc As Object 'Acrobat.CAcroPDDoc
Dim acroNewPdfDoc As Object 'Acrobat.CAcroPDDoc
Dim varOrigTotalPages As Long
Dim varNewTotalPages As Long
Dim strReportPathName As String
Dim strDoc2Insert As String
Dim i As Integer
Dim varsplit As Variant
Dim varSplit2 As Variant
Dim strMergeInputFile As String

On Error GoTo Errors

varsplit = Split(strFInalOutputDoc, "|", , vbTextCompare)
strMergeInputFile = varsplit(0)
strReportPathName = strPath
varsplit = Split(strMergeNames(0), "|", , vbTextCompare)

Set acroOrigPdfDoc = CreateObject("AcroExch.PDDoc")
Set acroNewPdfDoc = CreateObject("AcroExch.PDDoc")
'Open the first file. That is what will be appended to
' If acroOrigPdfDoc.Open(varSplit(0)) Then
If acroOrigPdfDoc.Open(strMergeInputFile) Then
For i = 0 To UBound(strMergeNames)
varsplit = Split(strMergeNames(i), "|", , vbTextCompare)
varOrigTotalPages = acroOrigPdfDoc.GetNumPages
If acroNewPdfDoc.Open(varsplit(0)) Then
'Get total # of pages to insert
varNewTotalPages = acroNewPdfDoc.GetNumPages
'Insert pages into original pdf
' objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 1, objCAcroPDDocSource.GetNumPages, 0
acroOrigPdfDoc.InsertPages varOrigTotalPages - 1, acroNewPdfDoc, 0, _
varNewTotalPages, False
'Save doc
' acroOrigPdfDoc.Save PDSaveIncremental, strMergeInputFile 'path doesn't matter, will save to original doc
acroOrigPdfDoc.Save PDSaveCopy, strMergeInputFile
acroNewPdfDoc.Close
Else
MsgBox "Failed to open doc "
End If
Next i
acroOrigPdfDoc.Save PDSaveCopy, strFInalOutputDoc
acroNewPdfDoc.Close
' acroOrigPdfDoc.Close
End If
' MsgBox "Pages added to " & path3
MergeThePDFs = True
'Close docs
If Dir(strPath) <> "" Then
Kill strPath
End If
Set acroOrigPdfDoc = Nothing
Set acroNewPdfDoc = Nothing

' rename the report cover file to the actual file name we want
Name strMergeInputFile As strPath

' delete individual files if the checkbox was checked on the form
If blnKillIndFiles Then
For i = 0 To UBound(strMergeNames)
varsplit = Split(strMergeNames(i), "|", , vbTextCompare)
Kill varsplit(0)
Next i
End If

ExitHere:
Exit Function
Errors:
MergeThePDFs = False
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure MergeThePDFs of Module basAcrobat2", , CurrentDb.Properties("AppTitle")
Resume ExitHere
Resume

End Function
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
VBA Code:
Function MergeThePDFs(ByRef strMergeNames() As String, strPath As String, strFInalOutputDoc As String, blnKillIndFiles As Boolean) As Boolean
Dim acroOrigPdfDoc As Object 'Acrobat.CAcroPDDoc
Dim acroNewPdfDoc As Object 'Acrobat.CAcroPDDoc
Dim varOrigTotalPages As Long
Dim varNewTotalPages As Long
Dim strReportPathName As String
Dim strDoc2Insert As String
Dim i As Integer
Dim varsplit As Variant
Dim varSplit2 As Variant
Dim strMergeInputFile As String

On Error GoTo Errors

varsplit = Split(strFInalOutputDoc, "|", , vbTextCompare)
strMergeInputFile = varsplit(0)
strReportPathName = strPath
varsplit = Split(strMergeNames(0), "|", , vbTextCompare)

Set acroOrigPdfDoc = CreateObject("AcroExch.PDDoc")
Set acroNewPdfDoc = CreateObject("AcroExch.PDDoc")
'Open the first file. That is what will be appended to
' If acroOrigPdfDoc.Open(varSplit(0)) Then
If acroOrigPdfDoc.Open(strMergeInputFile) Then
For i = 0 To UBound(strMergeNames)
varsplit = Split(strMergeNames(i), "|", , vbTextCompare)
varOrigTotalPages = acroOrigPdfDoc.GetNumPages
If acroNewPdfDoc.Open(varsplit(0)) Then
'Get total # of pages to insert
varNewTotalPages = acroNewPdfDoc.GetNumPages
'Insert pages into original pdf
' objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 1, objCAcroPDDocSource.GetNumPages, 0
acroOrigPdfDoc.InsertPages varOrigTotalPages - 1, acroNewPdfDoc, 0, _
varNewTotalPages, False
'Save doc
' acroOrigPdfDoc.Save PDSaveIncremental, strMergeInputFile 'path doesn't matter, will save to original doc
acroOrigPdfDoc.Save PDSaveCopy, strMergeInputFile
acroNewPdfDoc.Close
Else
MsgBox "Failed to open doc "
End If
Next i
acroOrigPdfDoc.Save PDSaveCopy, strFInalOutputDoc
acroNewPdfDoc.Close
' acroOrigPdfDoc.Close
End If
' MsgBox "Pages added to " & path3
MergeThePDFs = True
'Close docs
If Dir(strPath) <> "" Then
Kill strPath
End If
Set acroOrigPdfDoc = Nothing
Set acroNewPdfDoc = Nothing

' rename the report cover file to the actual file name we want
Name strMergeInputFile As strPath

' delete individual files if the checkbox was checked on the form
If blnKillIndFiles Then
For i = 0 To UBound(strMergeNames)
varsplit = Split(strMergeNames(i), "|", , vbTextCompare)
Kill varsplit(0)
Next i
End If

ExitHere:
Exit Function
Errors:
MergeThePDFs = False
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure MergeThePDFs of Module basAcrobat2", , CurrentDb.Properties("AppTitle")
Resume ExitHere
Resume

End Function
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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