CreateObject("Shell.Application").Namespace(ZipPath).CopyHere FilePath This method does not support passwords . You’ll get an unprotected ZIP every time. So we need an alternative. Method 1: Using Command‑Line 7‑Zip (Most Reliable) 7‑Zip is a free, powerful archiver. Its command‑line version 7z.exe supports AES‑256 encryption with passwords. Step 1: Install 7‑Zip Download and install 7‑Zip. The default path is C:\Program Files\7-Zip\7z.exe . Step 2: VBA Code Sub ZipWithPassword_7Zip() Dim FileToZip As String Dim ZipFileName As String Dim Password As String Dim SevenZipPath As String Dim Cmd As String ' --- Configuration --- FileToZip = "C:\Temp\Confidential.xlsx" ' File or folder to zip ZipFileName = "C:\Temp\Confidential.zip" Password = "MyStrongP@ssw0rd" SevenZipPath = "C:\Program Files\7-Zip\7z.exe"
' Command: a = add, -p = password, -ep1 = no full paths Dim cmd As String cmd = """" & rarPath & """ a -p" & pwd & " -ep1 """ & target & """ """ & source & """" excel vba zip file with password
Happy coding, and keep your data secure! CreateObject("Shell
' Delete existing ZIP if present If Dir(outputZip) <> "" Then Kill outputZip The default path is C:\Program Files\7-Zip\7z