You are on page 1of 1

Sub CreateZipWithPDFs()

Dim objShell As Object


Dim objFolder As Object
Dim objZipFile As Object
Dim zipFileName As String
Dim pdfFolderPath As String
Dim pdfFiles As String
Dim pdfFile As String

' Set the path to the folder containing the PDF files
pdfFolderPath = "C:\Path\To\PDF\Folder"

' Set the name of the zip file


zipFileName = "PDFs.zip"

' Create a Shell object


Set objShell = CreateObject("Shell.Application")

' Create a folder object for the PDF folder


Set objFolder = objShell.NameSpace(pdfFolderPath)

' Create a zip file object


Set objZipFile = objShell.NameSpace(pdfFolderPath & "\" & zipFileName)

' Get a list of PDF files in the folder


pdfFiles = Dir(pdfFolderPath & "\*.pdf")

' Loop through each PDF file and add it to the zip file
Do While pdfFiles <> ""
pdfFile = pdfFolderPath & "\" & pdfFiles
objZipFile.CopyHere objFolder.Items.Item(pdfFile)
pdfFiles = Dir
Loop

' Wait until all files are copied to the zip file
Do Until objZipFile.Items.Count = objFolder.Items.Count
Application.Wait Now + TimeValue("0:00:01")
Loop

' Clean up objects


Set objFolder = Nothing
Set objZipFile = Nothing
Set objShell = Nothing
End Sub

You might also like