... (1 Viewer)

jazsriel

Member
Local time
Today, 17:09
Joined
Dec 21, 2020
Messages
62
...
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:09
Joined
May 7, 2009
Messages
19,245
can you run a file from usb?
if you can you can download pdftk and combine your pdfs
using bat file.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:09
Joined
Oct 29, 2018
Messages
21,476
Hi. If you don't want to hard code a value, don't use constants, use variables instead. For example:

Dim DestFile As String

DestFile = Format(Date-1, "mm-dd-yy") & " Packet.pdf"

Hope that helps...
 
Last edited:

Eugene-LS

Registered User.
Local time
Tomorrow, 01:09
Joined
Dec 7, 2018
Messages
481
DestFile = Format(Date-1, "mm-dd-yy") & " Packet.pdf"
Harsh practice shows that it is better this way:
Code:
DestFile = Format(Date - 1, "yyyy-mm-dd") & " Packet.pdf"
... will be easier to sort files
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:09
Joined
May 7, 2009
Messages
19,245
change the sub to:
Code:
Sub MergePDFs(ByVal MyPath As String, ByVal MyFiles As String, ByVal Destination As String)
    ' Reference required: "VBE - Tools - References - Acrobat"
    ' --> Settings, change to suit
    'Const MyPath = "C:\Temp" ' Path where PDF files are stored
    'Const MyFiles = "1.pdf,2.pdf,3.pdf,4.pdf,5.pdf" ' List of PDFs to be merged
    'Const DestFile = "03-12-22 Packet.pdf" ' The name of the merged file
    ' <-- End of settings
    
    Dim a As Variant, i As Long, n As Long, ni As Long, p As String
    Dim AcroApp As New Acrobat.AcroApp, PartDocs() As Acrobat.CAcroPDDoc
    
    If Right(MyPath, 1) = "\" Then p = MyPath Else p = MyPath & "\"
    a = Split(MyFiles, ",")
    ReDim PartDocs(0 To UBound(a))
    
    On Error GoTo exit_
    If Len(Dir(p & DestFile)) Then Kill p & DestFile
    For i = 0 To UBound(a)
    ' Check PDF file presence
    If Dir(p & Trim(a(i))) = "" Then
    MsgBox "File not found" & vbLf & p & a(i), vbExclamation, "Canceled"
    Exit For
    End If
    ' Open PDF document
    Set PartDocs(i) = CreateObject("AcroExch.PDDoc")
    PartDocs(i).Open p & Trim(a(i))
    If i Then
    ' Merge PDF to PartDocs(0) document
    ni = PartDocs(i).GetNumPages()
    If Not PartDocs(0).InsertPages(n - 1, PartDocs(i), 0, ni, True) Then
    MsgBox "Cannot insert pages of" & vbLf & p & a(i), vbExclamation, "Canceled"
    End If
    ' Calc the number of pages in the merged document
    n = n + ni
    ' Release the memory
    PartDocs(i).Close
    Set PartDocs(i) = Nothing
    Else
    ' Calc the number of pages in PartDocs(0) document
    n = PartDocs(0).GetNumPages()
    End If
    Next
    
    If i > UBound(a) Then
    ' Save the merged document to DestFile
    If Not PartDocs(0).Save(PDSaveFull, p & DestFile) Then
    MsgBox "Cannot save the resulting document" & vbLf & p & DestFile, vbExclamation, "Canceled"
    End If
    End If
    
exit_:
    
    ' Inform about error/success
    If Err Then
    MsgBox Err.Description, vbCritical, "Error #" & Err.Number
    ElseIf i > UBound(a) Then
    MsgBox "The resulting file is created:" & vbLf & p & DestFile, vbInformation, "Done"
    End If
    
    ' Release the memory
    If Not PartDocs(0) Is Nothing Then PartDocs(0).Close
    Set PartDocs(0) = Nothing
    
    ' Quit Acrobat application
    AcroApp.Exit
    Set AcroApp = Nothing

End Sub

Private Sub Test()
    Dim path As String, files As String
    Dim file As String
    
    path = "C:\Temp\"
    file = Dir$(path & "*.pdf")
    Do While Len(file) <> 0
        files = files & file & ","
        file = Dir$
    Loop
    If Len(files) <> 0 Then
        files = Left$(files, Len(files) - 1)
        Call MergPDFs(path, files, "Merged.pdf")
    End If
End Sub
 

June7

AWF VIP
Local time
Today, 14:09
Joined
Mar 9, 2014
Messages
5,475
Button code works for me with a valid folder path that has PDF files. Have you step debugged?
 

June7

AWF VIP
Local time
Today, 14:09
Joined
Mar 9, 2014
Messages
5,475
Comment the On Error GoTo line and set a breakpoint in code. Step debug. What line is triggering that error?

I don't have Adobe Acrobat so can't actually run the merge procedure.

Indenting lines in the merge procedure would make it easier to read.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:09
Joined
Oct 29, 2018
Messages
21,476
I really am stuck and have no clue how to fix this.
I think you're having problems because you don't have Option Explicit at the top of your modules. Try adding one and see what happens. Once you fixed the errors, the code should work. It worked fine for me.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:09
Joined
May 7, 2009
Messages
19,245
There are the references I have turned on, maybe I am missing one
not Missing, Over-Referenced.
you only need Acrobat 10.0 Type library.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:09
Joined
May 7, 2009
Messages
19,245
i saw your Sub MergePDFs.
your last parameter (Destination) is not in your Code.
so you replaced it:

Sub MergePDFs(ByVal MyPath As String, ByVal MyFiles As String, ByVal DestFile As String)
 

Users who are viewing this thread

Top Bottom