vba help - Merge all pdf files from a folder into single PDF

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need your help , I have a folder which contain pdf files. I want to merge all PDF files into Single PDF.
Like Consolidation we do in excel. is it possible via vba, or any software required.


Snapshot of single file,
1608083462758.png



Below are the PDF files list of a folder ,which needs to Merge OR Consolidate.

1608083523145.png






Thanks
mg
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi Team,

I am using excel 2016, I see below vba library. I don't know Which library required for combining multiple pdf files.


1608089621479.png



Thanks
mg
 
Upvote 0
what about
VBA Code:
Sub JoinFiles()

Dim StrPath As String, FileName As String, FileExt As String
FileName = "Name It" ' New File name <<<<<
FileExt = ".pdf"
 StrPath = Environ("USERPROFILE") & "\Desktop\pdf Folder" ' replace with Your Folder Path
 
Call JoinFiles_In_One(StrPath, FileName, FileExt)

End Sub

Public Sub JoinFiles_In_One(FlderPath As String, FileName As String, FileExt As String)

Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim SourceFile As String, TargetFile As String
StrPath = FlderPath
PathArr = Split(StrPath, "\")
UstrPath = UBound(PathArr)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(StrPath)
    ' List Files
    N = 0
    SourceFile = ""
    TargetFile = ""
    For Each oFile In oFolder.Files
        If oFile.Name <> FileName & FileExt Then
            Open FlderPath & "\" & oFile.Name For Binary As #1
            N = N + 1
            SourceFile = Right(FileExt, Len(FileExt) - 1) & "_" & N
            SourceFile = String(LOF(1), 0)
            
            Get #1, 1, SourceFile
            Close #1
        TargetFile = TargetFile & SourceFile
       End If
    Next oFile
     'Mergge  File
         Open FlderPath & "\" & FileName & FileExt For Binary As #1
         Put #1, 1, TargetFile
         Close #1

End Sub
 
Upvote 0
or
Please go through
 
Upvote 0
Hi Dossfm0q,

Few pdf created from image file, few pdf created from outlook mail.

Needs to combine such type of PDFs. is it possible for such of scenario.





Thanks
mg
 
Upvote 0
Hi Dossfm0q,

Thanksk for your help , I have tested your given code, Macro run start to End.
It has created Final PDF as Name It, but it has single PDF in it. Last PDF Files.

But I see size has increased of Final output... but merged pdf missing.



Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top