Unzip Files (using VBA)

Vishesh's picture

Here is the small piece of code that unzips file into a target folder. Just use the following code procedure with your own parameter values.

Sub TestRun()
 
    'Change this as per your requirement

    Call UnZip("C:\Users\NC\Desktop\Vishesh\Test", "C:\Users\NC\Desktop\Vishesh\Test\TestZipFile.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

CVAR did the trick

error 91 solved by CVAR.
Thanks

Unzip error 91

I've tried this code in access vba - even using the CVar but still getting error 91.
If anyone has got this working would they please post a copy.
Thanks.

Thanks

This worked great. I was using a piece of code that called winzip32 but each call opened a windows explorer folder that I had to close manually. Your code was an easy drop in and eliminated that problem.

Thanks for the code!

I actually used it in an Access VBA environment. But I just started completely revamping an Access 2003 database where the client had been using an (purchased) OCX control to do this, and this cool little code snippet did the trick in seconds. I had to write and thank you for posting this - it made my day. I was not familiar with the NameSpace property you used so I learned something too!