VBA and PDF

N

npaulpatrick

I can't the following to work - says FileList not recognized?
'Copy all PDF files in source path into an array
arrPDFFileList = FileList(argPDFSourcePath, "*.pdf", False)
If IsEmpty(arrPDFFileList) Then MsgBox "No PDF files were found!",
vbCritical, "FILES NOT FOUND!": Call CommonEnd(True)


Public Function PDFCombineFiles(argPDFSourcePath As String,
argDestinationPath As String, argDestinationFileName As String)
'FUNCTION COMBINES ALL PDF FILES IN THE SOURCE PATH INTO A SINGLE PDF
DOCUMENT;
Dim arrPDFFileList() As Variant
Dim strFullPath As String
Dim intX As Integer
Dim intLastPage As Integer
Dim intNumPagesToInsert As Integer

'Copy all PDF files in source path into an array
arrPDFFileList = FileList(argPDFSourcePath, "*.pdf", False)
If IsEmpty(arrPDFFileList) Then MsgBox "No PDF files were found!",
vbCritical, "FILES NOT FOUND!": Call CommonEnd(True)




'Dimension required objects
Dim objAcroExchApp As Object
Dim objAcroExchPDDoc As Object
Dim objAcroExchInsertPDDoc As Object


'Establish object references
Set objAcroExchApp = CreateObject("AcroExch.App")
Set objAcroExchPDDoc = CreateObject("AcroExch.PDDoc")


'Optionally show the Acrobat Exchange window - just to see if it works
'oAcroExchApp.Show


'Open the first file in the list
strFullPath = argPDFSourcePath & arrPDFFileList(1)
objAcroExchPDDoc.Open strFullPath


'Initialize a loop through each file in the PDF folder
For intX = 1 To UBound(arrPDFFileList)


'Concatenate source path and file name into a single string
strFullPath = argPDFSourcePath & arrPDFFileList(intX)


'If intX > 0 Then
If intX > 1 Then


'Sequentially open each remaining file in the directory
objAcroExchPDDoc.Open strFullPath


'Get the total pages less one for the last page num [zero
based]
intLastPage = objAcroExchPDDoc.GetNumPages - 1


'Obtain an object reference to the Exchange program in PDF
Set objAcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")


'Open the file to insert
objAcroExchInsertPDDoc.Open strFullPath


'Count the pages in the current document to insert
intNumPagesToInsert = objAcroExchInsertPDDoc.GetNumPages


'Insert the pages
objAcroExchPDDoc.InsertPages intLastPage,
objAcroExchInsertPDDoc, 0, intNumPagesToInsert, True


'Close the document
objAcroExchInsertPDDoc.Close
End If
Next intX


'Save the entire document using SaveFull [0x0001 = &H1]
objAcroExchPDDoc.Save &H1, argDestinationPath & argDestinationFileName


'Close the PDDoc
objAcroExchPDDoc.Close


'Close Acrobat Exchange
objAcroExchApp.Exit


'Toss objects and release memory
Set objAcroExchApp = Nothing
Set objAcroExchPDDoc = Nothing
Set objAcroExchInsertPDDoc = Nothing


End Function
 
N

NickHK

It looks like FileList is a function that returns an array of file names.
As you have not included it, that's just a guess.
But I suspect you are missing it, so you will need to replicate whatever it
was designed to do.

NickHK

I can't the following to work - says FileList not recognized?
'Copy all PDF files in source path into an array
arrPDFFileList = FileList(argPDFSourcePath, "*.pdf", False)
If IsEmpty(arrPDFFileList) Then MsgBox "No PDF files were found!",
vbCritical, "FILES NOT FOUND!": Call CommonEnd(True)


Public Function PDFCombineFiles(argPDFSourcePath As String,
argDestinationPath As String, argDestinationFileName As String)
'FUNCTION COMBINES ALL PDF FILES IN THE SOURCE PATH INTO A SINGLE PDF
DOCUMENT;
Dim arrPDFFileList() As Variant
Dim strFullPath As String
Dim intX As Integer
Dim intLastPage As Integer
Dim intNumPagesToInsert As Integer

'Copy all PDF files in source path into an array
arrPDFFileList = FileList(argPDFSourcePath, "*.pdf", False)
If IsEmpty(arrPDFFileList) Then MsgBox "No PDF files were found!",
vbCritical, "FILES NOT FOUND!": Call CommonEnd(True)




'Dimension required objects
Dim objAcroExchApp As Object
Dim objAcroExchPDDoc As Object
Dim objAcroExchInsertPDDoc As Object


'Establish object references
Set objAcroExchApp = CreateObject("AcroExch.App")
Set objAcroExchPDDoc = CreateObject("AcroExch.PDDoc")


'Optionally show the Acrobat Exchange window - just to see if it works
'oAcroExchApp.Show


'Open the first file in the list
strFullPath = argPDFSourcePath & arrPDFFileList(1)
objAcroExchPDDoc.Open strFullPath


'Initialize a loop through each file in the PDF folder
For intX = 1 To UBound(arrPDFFileList)


'Concatenate source path and file name into a single string
strFullPath = argPDFSourcePath & arrPDFFileList(intX)


'If intX > 0 Then
If intX > 1 Then


'Sequentially open each remaining file in the directory
objAcroExchPDDoc.Open strFullPath


'Get the total pages less one for the last page num [zero
based]
intLastPage = objAcroExchPDDoc.GetNumPages - 1


'Obtain an object reference to the Exchange program in PDF
Set objAcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")


'Open the file to insert
objAcroExchInsertPDDoc.Open strFullPath


'Count the pages in the current document to insert
intNumPagesToInsert = objAcroExchInsertPDDoc.GetNumPages


'Insert the pages
objAcroExchPDDoc.InsertPages intLastPage,
objAcroExchInsertPDDoc, 0, intNumPagesToInsert, True


'Close the document
objAcroExchInsertPDDoc.Close
End If
Next intX


'Save the entire document using SaveFull [0x0001 = &H1]
objAcroExchPDDoc.Save &H1, argDestinationPath & argDestinationFileName


'Close the PDDoc
objAcroExchPDDoc.Close


'Close Acrobat Exchange
objAcroExchApp.Exit


'Toss objects and release memory
Set objAcroExchApp = Nothing
Set objAcroExchPDDoc = Nothing
Set objAcroExchInsertPDDoc = Nothing


End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top