Quantcast
Channel: PDFCreator - pdfforge forums
Viewing all articles
Browse latest Browse all 2622

Mergeing pdf files with vba

$
0
0

I am doing a project using VBA code in Excel - I am new to vba language.

I am struggling with my last macro - I need a macro to merge all pdf files that are located in the folder c:\TempFiles. want to use the refference pdf creator.com.tlb

I have no idea how to write such a vba code - I am a total beginner. I would also want to mention that I prefer a vba macro for a specific folder c:\TempFiles and not a vba code that opens a folder dialog.

The vba should merge all the pdf files in c:\TempFiles no matter the names of the files.

I found after a search a code but it is not exactly what i need

Sub mergePDF()

Dim outPath$
Dim folder As String
Dim PDFfilename As String

folder = ThisWorkbook.Path & "\raw folder\"    'CHANGE AS REQUIRED
If Right(folder, 1) <> "\" Then folder = folder & "\"
   
PDFfilename = Dir(folder & "*.pdf", vbNormal)

outPath = ThisWorkbook.Path & "\Final Merged\outputFile.pdf"

Dim oPDF As PdfCreatorObj
Set oPDF = New PdfCreatorObj

While Len(PDFfilename) <> 0
    oPDF.AddFileToQueue folder & PDFfilename
    PDFfilename = Dir()  ' Get next matching file
Wend

Debug.Print "oPDF isinstancerunning: " & oPDF.IsInstanceRunning ' close Excel and open if true.

'On Error GoTo EndSub ' this is commented out for debuging purposes
Dim q As PDFCreator_COM.Queue
Set q = New PDFCreator_COM.Queue

q.Initialize
q.WaitForJobs 2, 10

Debug.Print "q.Count: " & q.Count ' here it prints either 1 or 2. Should always be 2.

q.MergeAllJobs

Dim job As PDFCreator_COM.PrintJob

While q.Count > 0
Set job = q.NextJob
job.SetProfileByGuid ("DefaultGuid")
job.ConvertTo (outPath)
Debug.Print job.IsFinished
Debug.Print job.IsSuccessful
Debug.Print "q.Count3: " & q.Count
Wend
EndSub:
q.ReleaseCom

MsgBox ("MEGED FILE HAS BEEN SAVED IN" & ThisWorkbook.Path & "\Final Merged")
End Sub

I need another macro which just combinee all pdf pages in c:\tempfiles.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 2622

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>