Convert VB PDF merge function to VBA

Posted on 2006-05-03
Medium Priority
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.
  • 3
  • 2
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16598751
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

Leigh Purvis earned 2000 total points
ID: 16598993
Adapting what they offer and getting rid of the Common dialog in preference of the goold ol' http://www.mvps.org/access/api/api0001.htm
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.
ID: 16605469
From the programmer who actually implemented it:
Great.  That works wonderfully :)  

Thank you
LVL 44

Expert Comment

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

(And yours too Jim :-)
LVL 38

Author Comment

by:Jim P.
ID: 16606405

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 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