'// ParamArray であたえられたファイルたち(paths)を
'// 7-zip でパスワード(pass_word)付きZipにする
Sub CreateZipWithPassword(ByVal pass_word As String, ParamArray paths())
Dim sevenZipPath As String '-- 7-Zipのパス
sevenZipPath = "C:\Program Files\7-Zip\7z.exe"
Dim zipArchiveName As String '-- 出力するZipファイル名
zipArchiveName = Format(Now, "yyyy-mm-dd[hnnss]") & ".zip"
Dim zipArchivePath As String '-- 出力するZipファイルのパス
With CreateObject("Scripting.FileSystemObject")
zipArchivePath = .BuildPath(.GetParentFolderName(paths(0)), zipArchiveName)
End With
Dim i As Long
Dim filesPathStr As String
For i = LBound(paths) To UBound(paths)
'' アーカイブするファイルたちのパスを半角スペースでつなげる
filesPathStr = filesPathStr & GetExistsPathWQ(paths(i)) & " "
Next i
Dim cmdLine As String '-- コマンドライン
cmdLine = AddWQ(sevenZipPath) & " a -tzip " & AddWQ(zipArchivePath) & _
" " & filesPathStr & "-p" & pass_word
'' コマンド実行
Shell cmdLine, vbHide
MsgBox "Zipファイル作成完了!", vbInformation
End Sub