VBA Code to zip files:
Private Sub ZipFile_FX(ZipFileName As String, fileToBeZipped As String)
Const ZIPEXELOCATION = "c:\program files\winzip\winzip32.exe"
Shell ZIPEXELOCATION & " -a " & Chr(34) & ZipFileName & Chr(34) & _
" " & Chr(34) & fileToBeZipped & Chr(34), vbNormalFocus
End Sub
sub zips()
Call ZipFile_FX("c:\b.zip", "c:\b.xls")
end sub
Const ZIPEXELOCATION = "c:\program files\winzip\winzip32.exe"
Shell ZIPEXELOCATION & " -a " & Chr(34) & ZipFileName & Chr(34) & _
" " & Chr(34) & fileToBeZipped & Chr(34), vbNormalFocus
End Sub
sub zips()
Call ZipFile_FX("c:\b.zip", "c:\b.xls")
end sub
Code to unzip a file:
ReplyDeleteSub TestRun()
Sheets("Unzip").Select
'Change this as per your requirement
Call UnZip("C:\Zip Files", "C:\Zip Files\Test.zip")
End Sub
Sub UnZip(strTargetPath As String, Fname As Variant)
Dim oApp As Object
Dim FileNameFolder As Variant
If Right(strTargetPath, 1) <> Application.PathSeparator Then
strTargetPath = strTargetPath & Application.PathSeparator
End If
FileNameFolder = strTargetPath
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items
End Sub