Originally Posted by
June7
Your code is constructing a filename as recordsSomethingRecord.pdf.
If records is a folder then it needs to be followed by a \.
DoCmd.OutputTo acOutputForm, "Form1", acFormatPDF, "C:\Fortest\records\" & [Forms]![Form1]![txtname] & " Record.pdf", True (One PDF)
DoCmd.OutputTo acOutputForm, "Form2", acFormatPDF, "C:\Fortest\records\" & [Forms]![Form2]![txtname] & " Record.pdf", True (2nd PDF)
Then I suppose the SourceFolder variable would be set to: "C:\Fortest\records"
Set SourceFolder = fso.GetFolder("C:\Fortest\records")
Hi June,
Thanks for your reply. But still not able to make it.
When i run the code. It comes out "Run time Error 429, ActiveX component can't create object"
Code:
Sub BatchMergePDF()
Dim fso As Object, SourceFolder As Object, SFolder As Object, SSFolder As Object, SSSFolder As Object, PDFile As Object
'Relies on the Adobe Acrobat 6.0 Type Library
Dim objCAcroPDDocDestination As Acrobat.AcroPDDoc
Dim objCAcroPDDocSource As Acrobat.AcroPDDoc
Dim i As Integer, booMerge As Boolean
'Initialize the objects
Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder("C:\Users\records\1\")
For Each SFolder In SourceFolder.subfolders
For Each SSFolder In SFolder.subfolders
If SSFolder.Name <> "Soils & Aggregate" Then
i = 1
For Each PDFile In SSFolder.Files
If i = 1 Then
objCAcroPDDocDestination.Open SSFolder.Path & "\" & PDFile.Name
End If
If i > 1 Then
objCAcroPDDocSource.Open SSFolder.Path & "\" & PDFile.Name
objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
objCAcroPDDocSource.Close
End If
i = i + 1
Next
objCAcroPDDocDestination.Save 1, SFolder.Path & "\" & SSFolder.Name & ".pdf"
objCAcroPDDocDestination.Close
Else
For Each SSSFolder In SSFolder.subfolders
i = 1
For Each PDFile In SSSFolder.Files
If i = 1 Then
objCAcroPDDocDestination.Open SSSFolder.Path & "\" & PDFile.Name
End If
If i > 1 Then
objCAcroPDDocSource.Open SSSFolder.Path & "\" & PDFile.Name
objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
objCAcroPDDocSource.Close
End If
i = i + 1
Next
objCAcroPDDocDestination.Save 1, SFolder.Path & "\Soils & Aggregate " & SSSFolder.Name & ".pdf"
objCAcroPDDocDestination.Close
Next
End If
Next
Next
Debug.Print SFolder.Name
Set PDFile = Nothing
Set SFolder = Nothing
Set SSFolder = Nothing
Set SSSFolder = Nothing
Set SourceFolder = Nothing
Set fso = Nothing
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
End Sub