The PODA Blog

News, views and articles from our membership

Zip and Unzip Using Shell32

Posted by Derek Mang on May 12th, 2009

Zip files are pretty common.   We receive them as email attachments, download from the Internet, create them to conserve space, email out to others…

Winzip is used by many - including me - to zip or unzip typically because it works well and integrates into Windows explorer becoming available within the context menu for files and folders.

I have several MS Office addins that ”Shell” out to zip and / or  unzip files as needed, always using ”ShellAndWait” code that was  found on the internet and customized to fit (although not a lot was needed!).  In case you’re not familiar with this, winzip is invoked via Shell, complete with commandline arguments and source and target information. 

And this works well, unless you don’t have Winzip installed…which is exactly what happened recently with a small addin I had put together for a colleague.  The addin tested out fine for me of course, and we were both surprised when it failed on the other PC. 

So I went looking, as is often the case when one method does not do the job.

What I found was that the windows file shell32.dll can zip and unzip files, among a variety of other things.  This was a pleasant surprise, not having to use a third party product. Even better, the code sample below was used as is, which is always a plus!!  The code is also somewhat simpler that the ShellandWait code.  Note that you will need to set reference to “Microsoft Shell Controls and Automation”.

To the author ….Thanks for sharing!!  Your efforts have really saved mine! This is also going into an Outlook addin currently under development.

Here’s the link.

http://www.vbforums.com/showthread.php?t=534899

Posted in VBA | No Comments »