CreateZipFiles_7Zip

Create zip from list of files listed in List_of_Files separated by comma.
The list needs to have full path and file names of all files to be compressed
Code will create a temp file needed having list of files (you do not need to create that), then call 7za to compress all these files
7za,exe (found in attached zip) expected to be in a folder called "Resources" next to that workbook.
Function does not wait for archive to finish

Sub CreateZipFiles_7Zip(List_of_Files, ZipFile, Optional Sep1=",")
 ' Creates a Zip file having all files listed in List_of_Files that is separated by comma
 ' First function needs to have a txt file having list of files
 Fii = Replace(List_of_Files, Sep1, vbcrlf)
 Fi2 = FixPath(FixPath() & "Resources") & "TempFiles.txt"
 If IsThere1(Fi2, True, True) Then Kill Fi2
 Close
 Open Fi2 For Output As #1
 Print #1, Fii
 Close
 DoEvents
 Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
 DoEvents
 ' Then we call to archive all these files
 Cmd1 = Chr(34) & FixPath(FixPath() & "Resources") & "7za.exe" & Chr(34)
 Cmd2 = " a -tzip "
 Cmd3 = Chr(34) & ZipFile & Chr(34)
 Cmd4 = " @" & Chr(34) & Fi2 & Chr(34)
 Shell Cmd1 & Cmd2 & Cmd3 & Cmd4, vbHide
 DoEvents
 Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
 DoEvents
 Kill Fi2
End Sub

List_of_Files, ZipFile, Optional Sep1

Views 434 Downloads 153

'FixPath', 'IsThere1', '7za', 'Zip', '7zip', '7z', '7za.exe', 'archive', 'compress', 'files', 'lit of files'

ANmarAmdeen
324
Attachments
File System VBA-Excel
Revisions

v1.0