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

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
863
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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
863
Office Version
  1. 2010
Platform
  1. Windows
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
 

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
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
 

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
or
Please go through
 

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
863
Office Version
  1. 2010
Platform
  1. Windows
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
 

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
863
Office Version
  1. 2010
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,526
Messages
5,636,829
Members
416,944
Latest member
bradb2887

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
Top