Zip and Unzip Using VB5 or VB6

This code shows how to use the freeware InfoZip Zip32.DLL and Unzip32.DLL files from the website. I've included the two dll's in the download file at the end of this article.

The InfoZip DLL's are open-source DLL's that are available for programmers to utilise free of charge. They are standard C DLL's and were very tricky/impossible to interface with VB until VB5/6 offered the 'addressof' operator.

About this Code

I based this code on the Zip/Unzip examples that come with the downloadable DLL's and encapsulated that code into re-usable class modules that can either be used in an ActiveX DLL, or just placed into your project as required. The downloadable project contains the source-code for an ActiveX DLL called CGZipLibrary and a sample project which uses that DLL.

The example program simply takes everything in it's own directory and zip's it into a file.

You can then unzip this file straight into the TEMP directory. You can check the structure of the Zip file using WinZip (or similar) if you want to check that the Zip is intact (I've had no problems with it at all).

The Class Modules CGZipFiles and CGUnzipFiles have a lot of properties - it's worth reading through the code in these classes to learn how to get the best from them.

A sample piece of code using the Zip class could be as simple as :

Dim oZip as CGZipFiles

set oZip = new CGZipFiles

oZip.ZipFileName = "\MyZip.Zip"
oZip.AddFile "c:\mystuff\myfiles\*.*"
oZip.AddFile "c:\mystuff\mymedia\*.wav"

If oZip.MakeZipFile <> 0 then
   MsgBox oZip.GetLastMessage
End If

set oZip = nothing


The code for Unzipping files is just as straight-forward :

Dim oUnZip as CGUnZipFiles

set oUnZip = new CGUnZipFiles

oUnZip.ZipFileName = "\MyZip.Zip"
oUnZip.ExtractDir = App.Path ' or whatever you like !
oUnZip.HonourDirectories = true ' keep dir structure
If oUnZip.UnZip <> 0 then 
  MsgBox oUnZip.GetLastMessage
End If

set oUnZip = nothing

Note : This code is provided as-is - I know that there are a few bugs in the interface to the Zip/Unzip DLL's (including a frustrating one that's got a real cludge work around - see if you can spot it). It's designed as a starting point to allow you to use Zip and Unzip functionality in your programs. You should really place the Zip32.DLL and Unzip32.DLL into your \windows\system directory (although you can just have them in the same directory as the ActiveX DLL)

I've been a version of this code for several weeks in a production application and it's just been superb.

I hope you enjoy the code!



  • It works in MS Excel 2013 VBA under Windows 10.

    Posted by DelGesu on 10/04/2015 08:49pm

    Great tool ! It works in MS Excel 2013 VBA under Windows 10. Import CGUnzipFiles.cls, CGZipFiles.cls and CodeModule.bas in your .xlsm or xlsb file via VBE and paste Unzip32.dll in C:\Windows\SysWOW64. No need to register anything. Thanks for sharing.


    Posted by Md. Abdul Hannan on 11/24/2014 10:28pm

    Zip code works very nice.register the CGZipLibrary.dll Thanks

  • Test Engineer

    Posted by Travis Kintz on 07/05/2013 11:44am

    How would I use this to zip a Folder and all folders in it?

  • Password

    Posted by thenndral on 01/10/2013 10:07pm

    It works great. How Can I use Password for Zip/Unzip? Please let me know, Is it possible?

  • Unzip using vb6

    Posted by Willie on 12/06/2012 09:19am

    hi there all. I am new to vb6, and have succesfully built my first karaoke player. In short, I am trying desperately to add only unzip to my vb6 app.... Basically, i select the zip file from a list, add the full path to a variable. I want to unzip this to my app.path & "\Now" folder... this example seems very straight forwARD, BUT I CANNOT GET IT WORKING ...? Please can someone tell me: a) what dependancies i need to unzip only b) where to store the dependancies (system32 or app path) c) What code to add to unzip a zip file to my folder please...?

  • Mr

    Posted by Jack on 10/20/2012 12:12am

    Looks very useful if only I could register the CGZipLibrary.dll.

  • Mr

    Posted by Rob Crombie on 07/31/2012 06:38am

    Thanks for sharing. Great solution.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Thanks to the Internet of Things (IoT), physical assets are turning into participants in real-time global digital markets. The countless types of assets around us will become as easily indexed, searched and traded as any online commodity. While some industries will be tougher to transform than others – those with physical limitations, such as manufacturing, will be harder to digitize – untold economic opportunities exist for growth and advancement. Our research shows this will create a new "Economy …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date