Convert VB PDF merge function to VBA

There is a VB function/module to merge multiple PDF documents to a single PDF located at
http://www.pdfonline.com/absolutenews/anmviewer.asp?a=5&z=1

The full source code is at:
http://www.pdfonline.com/absolutenews/articlefiles/5-VB_Merge.zip

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.
LVL 38
Jim P.Asked:
Who is Participating?
 
Leigh PurvisDatabase DeveloperCommented:
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)
        Else
            Exit Do
        End If
    Loop

    ' 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
   
ButtonMergeFiles_Click_End:

    Set oProcessor = Nothing
    Exit Function
   
ButtonMergeFiles_Click_Err:
    DoCmd.Hourglass False

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

End Function

   
0
 
Leigh PurvisDatabase DeveloperCommented:
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?
0
 
Jim P.Author Commented:
From the programmer who actually implemented it:
----------------------------------
Great.  That works wonderfully :)  

Thank you
0
 
Leigh PurvisDatabase DeveloperCommented:
He's welcome...
May all his days get brighter and brighter ;-)

(And yours too Jim :-)
0
 
Jim P.Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.