PDA

View Full Version : Zip a file via VB?



entwined
01-03-2012, 09:48 PM
Is there any way to zip an excel file or any files through VB macro only and without WinZip installed nor any special stand alone zipping tool that can be shelled.

Thanks...

Jan Karel Pieterse
01-03-2012, 10:18 PM
Yes you can. I have a class module that does this to Office files to extract its contents and put them back together again. Modify to suit your need:
http://www.jkp-ads.com/articles/Excel2007FileFormat02.asp

Kenneth Hobs
01-04-2012, 06:47 AM
Depending on your windows version:
http://www.rondebruin.nl/zip.htm

or

http://blogs.ugidotnet.org/fgiossi/archive/2009/03/27/how-to-zip-a-file-using-visual-basic-6-and.aspx

Jan Karel Pieterse
01-04-2012, 09:09 AM
Guess where my code came from :-)

Kenneth Hobs
01-04-2012, 09:50 AM
Jan, I am sure that your class is great as is most of your code!

entwined
01-04-2012, 04:30 PM
Thank you for that Jan. I tried fetching the code for zipping the file only but I encountered an error (runtime error 91). Would you please provide just for the zipping files alone as the zipped file is my final touch and no unzipping and zipping 'em back necessary.

Thanks... :)

Jan Karel Pieterse
01-05-2012, 03:19 AM
Rather that updating my code, I'd suggest to use Ron de Bruin's simpler code which only zips:
http://www.rondebruin.nl/windowsxpzip.htm

entwined
01-05-2012, 10:36 PM
Thank you again. Sorry but one last request though. :)

Rather than browsing the files you want to zip, I would like it to just prompt an input box and I will just paste the path of the files there (e.g. "D:\zipping folder\". The "zipping folder" folder contains the files themselves). Would that be possible? I pray so. :)

Thanks so much. You really did help me a lot!

Kenneth Hobs
01-06-2012, 02:08 PM
First, try Ron's Zip_All_Files_in_Folder_Browse() and post back. The Windows operating system will make a difference.