I use this code...works great.
usage:
UnZip vFile, sTargetDir
Code:
Public Sub UnZip( _
ZipFile As String, _
Optional TargetFolderPath As String = vbNullString, _
Optional OverwriteFile As Boolean = False)
On Error GoTo ErrHandler
Dim oApp As Object
Dim FSO As Object
Dim fil As Object, fMaxFile As Object
Dim DefPath As String
Dim strDate As String
Set FSO = CreateObject("Scripting.FileSystemObject")
If Len(TargetFolderPath) = 0 Then
DefPath = Application.Path & ""
Else
If FSO.folderexists(TargetFolderPath) Then
DefPath = TargetFolderPath & ""
Else
Err.Raise 53, , "Folder not found"
End If
End If
If FSO.FileExists(ZipFile) = False Then
MsgBox "System could not find " & ZipFile _
& " upgrade cancelled.", _
vbInformation, "Error Unziping File"
Exit Sub
Else
'Extract the files into the newly created folder
Set oApp = CreateObject("Shell.Application")
With oApp.NameSpace(ZipFile & "")
If OverwriteFile Then
For Each fil In .Items
'If fMaxFile Is Nothing Then Set fMaxFile = fil
'If fil.Size > fMaxFile.Size Then Set fMaxFile = fil 'FIND THE LARGEST FILE
If FSO.FileExists(DefPath & fil.Name) Then
Kill DefPath & fil.Name
End If
Next
End If
oApp.NameSpace(CVar(DefPath)).CopyHere .Items
'Set UnZip = fMaxFile
End With
On Error Resume Next
Kill Environ("Temp") & "Temporary Directory*"
'clear mem
Set oApp = Nothing
Set FSO = Nothing
Set fil = Nothing
'Set fMaxFile = Nothing
End If
ExitProc:
On Error Resume Next
Set oApp = Nothing
Exit Sub
ErrHandler:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Unexpected error"
End Select
Resume ExitProc
Resume
End Sub