Convert VB PDF merge function to VBA

Posted on 2006-05-03
Last Modified: 2008-01-09
There is a VB function/module to merge multiple PDF documents to a single PDF located at

The full source code is at:

And there is more before the "Private Sub ButtonCheckFileEncryption_Click()"
sucha as:
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form ep4proc
   BorderStyle     =   1  'ŒÅ’è(ŽÀü)
   Caption         =   "PDF Processor sample program (VB)"

We'd like to be able to convert it to an Access VBA function.
Question by:Jim P.
    LVL 44

    Expert Comment

    by:Leigh Purvis
    Hi Jim

    Were you looking at that source code in Notepad?
    That waffle between the ------'s just looks like a Form's source.

    The code itself looks alright - except for a need to reference the easyPdfSdk and a common dialog ActiveX (blurgh).

    Is there anything in particular that is failing once it's in Access?
    LVL 44

    Accepted Solution

    Adapting what they offer and getting rid of the Common dialog in preference of the goold ol'
    something like this?

    Function PDFMerge()

        Dim i As Long
        Dim files As New Collection
        Dim inFile1 As String
        Dim inFile2 As String
        Dim strFilter As String
        Dim strFile As String
        Dim oProcessor As Object 'BEPPROCLib.PDFProcessor
        ' For file merging
        MsgBox "Please select files to merge now." + vbLf + vbLf + _
               "There will be multiple file dialog coming up. Press cancel when finished.", vbOKOnly + vbInformation
        ' Accumulate PDF files until user cancels.
        strFilter = AddFilterItem(strFilter, "PDF Files (PDF)", "*.pdf")
        Do While (True)
            strFile = Nz(CommonFileOpenSave(, , strFilter, , , , "Select a PDF File to merge"))
            If Len(strFile) > 0 Then
                files.Add (strFile)
                Exit Do
            End If

        ' You need at least two files for appending
        If (files.Count < 2) Then
            If (files.Count = 1) Then
                MsgBox "You need at least two files for merging!", vbOKOnly + vbInformation
            End If
            Exit Function
        End If
        MsgBox "Now please specify where to save", vbOKOnly + vbInformation
        ' Ask for the destination file name
        strFile = Nz(CommonFileOpenSave(, , strFilter, , , , "Select a location to save", , False))
        If (Len(strFile) = 0) Then
            ' User didn't choose a save file location
            Exit Function
        End If

        DoCmd.Hourglass True
        On Error GoTo ButtonMergeFiles_Click_Err

        Set oProcessor = CreateObject("easyPdfSdk.PDFProcessor")
        ' Merge all files
        inFile1 = files(1)
        For i = 2 To files.Count
            inFile2 = files(i)
            Call oProcessor.Merge(inFile1, files(i), strFile)
            inFile1 = strFile
        Next i

        DoCmd.Hourglass False
        MsgBox "Done", vbOKOnly + vbInformation

        Set oProcessor = Nothing
        Exit Function
        DoCmd.Hourglass False

        MsgBox err.Description + " (" + CStr(err.Number) + ")", vbOKOnly + vbInformation
        Resume ButtonMergeFiles_Click_End

    End Function

    LVL 38

    Author Comment

    by:Jim P.
    From the programmer who actually implemented it:
    Great.  That works wonderfully :)  

    Thank you
    LVL 44

    Expert Comment

    by:Leigh Purvis
    He's welcome...
    May all his days get brighter and brighter ;-)

    (And yours too Jim :-)
    LVL 38

    Author Comment

    by:Jim P.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now