KenCriss
Active Member
- Joined
- Jun 6, 2005
- Messages
- 326
The following code works great for zipping all files in a folder. But I have a need to feed a list of files into the macro instead of zipping the entire folder. Is there a way to revise the code to do this? Not sure it matters, but all the files will have an extension of .DAT. Thanks for any advice.
VBA Code:
Sub CreateZipFile(folderToZipPath As Variant, zippedFileFullName As Variant)
Dim ShellApp As Object
'Create an empty zip file
Open zippedFileFullName For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'Copy the files & folders into the zip file
Set ShellApp = CreateObject("Shell.Application")
ShellApp.Namespace(zippedFileFullName).CopyHere ShellApp.Namespace(folderToZipPath).items
'Zipping the files may take a while, create loop to pause the macro until zipping has finished.
On Error Resume Next
Do Until ShellApp.Namespace(zippedFileFullName).items.Count = ShellApp.Namespace(folderToZipPath).items.Count
Application.Wait (Now + TimeValue("0:00:01"))
Exit Do
Loop
On Error GoTo 0
End Sub
Sub MakeZip()
Call CreateZipFile("U:\WS_Users\KWC\Temp\TEST", "U:\WS_Users\KWC\Temp\MyCompanyZip.zip")
MsgBox "Done!"
End Sub