by Mason Reece Soiza (2 Submissions)
Category: Files/File Controls/Input/Output
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
This code will zip any file or folder
Private Sub Command1_Click()
CreateEmptyZip "c:\testzip.zip"
With CreateObject("Shell.Application")
.NameSpace("c:\testzip.zip").CopyHere "c:\FirePassword.exe"
' .NameSpace("c:\testzip.zip").CopyHere .NameSpace(FolderName).items 'use this line if we want to zip all items in a folder into our zip file
End With
' All done!
End Sub
Public Sub CreateEmptyZip(sPath)
Dim strZIPHeader As String
strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0) ' header required to convince Windows shell that this is really a zip file
With CreateObject("Scripting.FileSystemObject")
.CreateTextFile(sPath).Write strZIPHeader
End With
End Sub