How can I GZip compress a file from Excel VBA using code in an .xla file only?

前端 未结 5 1315
情深已故
情深已故 2021-01-06 08:32

I need to be able to GZip compress a file in an Excel VBA function. Specifically I need to be able to use the \'deflate\' algorithm.

Is there a way to do this withou

5条回答
  •  Happy的楠姐
    2021-01-06 09:15

    VBA (which is really a dialect of VB6) is slow for these kind of applications. I remember I once implemented Shannon-Fano algorithm on VB6 and on C, the C version was about 10 times faster, even after being turned into a DLLMain and called from there rather than on a command-line executable.

    There are lots of COM DLLs that provide compression services, both open source and shareware, and some of them implement GZIP's deflate algorithm. It'd be really simple to just call one function from such a DLL from your VBA code to do the compression on your behalf.

    I understand your being reluctant on using something external to your application, though in this case you might have to apply an exception for performance's sake.

    In an effort to completely spoil your fun, examine file ZIPFLDR.DLL on windows\system32. you may also like to take a look at these links:

    • This has an example of how to do what you want (zipping using windows built-in ZIP capabilities) from VB.NET, it shouldn't be much different from VBA or VB6: Transparent ZIP with DLL call
    • This one has a sample application on VB6 using windows built-in capabilities to zip (in ZIP rather than GZIP format, of course): Using Windows XP "Compressed Folder" shell extension to work with .zip files

    Found both thru googling, you should be able to find more/better examples.

提交回复
热议问题