Dim wsh As Object Set wsh = CreateObject("WScript.Shell") wsh.Run cmd, 0, True
' --- Build command --- ' a = add, -tzip = zip format, -p = password, -mx=9 = max compression Cmd = """" & SevenZipPath & """ a -tzip """ & ZipFileName & """ """ & _ FileToZip & """ -p" & Password & " -mx=9 -y" excel vba zip file with password
Sub BatchZipWithPassword() Dim folderPath As String Dim outputZip As String Dim pwd As String Dim sevenZipExe As String Dim cmd As String folderPath = "C:\Reports\2026-04\" ' Folder to compress outputZip = "C:\Archives\Reports_April.zip" pwd = InputBox("Enter ZIP password:", "Security") If pwd = "" Then Exit Sub Dim wsh As Object Set wsh = CreateObject("WScript
Sub ZipWithPassword_WinRAR() Dim rarPath As String Dim source As String Dim target As String Dim pwd As String rarPath = "C:\Program Files\WinRAR\rar.exe" source = "C:\Temp\DataFolder" target = "C:\Temp\Secure.rar" ' WinRAR creates .rar, not .zip pwd = "Secret123" -tzip = zip format
Happy coding, and keep your data secure!