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

I need GZip to compress a file in Excel VBA function. In particular, I need to be able to use the deflate algorithm.

Is there a way to do this without running a command line application? Without dependence on external tools, the code will be more reliable.

Ideally, the code will use the pre-installed functions of the VBA or COM library - I do not want to implement this logic myself or install DLLs, etc.

If possible, I want the function to be installed as simple as adding .xla to available Excel add-ins. No DLLs, EXEs, registry entries, etc. are required.

Edit Can I use .NET GZipStream for this?

+3
source share
5 answers

VBA (which is actually a dialect of VB6) is slow for such applications. I remember that once I implemented the Shannon-Fano algorithm on VB6 and C, the C version was about 10 times faster, even after it was converted to DLLMain and called from there, and not to an executable file from the command line.

There are many COM libraries that provide compression services, both open source and shareware, and some of them implement the GZIP deactivation algorithm. It would just be easy to call one function from such a DLL from your VBA code to perform compression on your behalf.

, - , .

, ZIPFLDR.DLL windows\system32. :

googling, / .

+4

, , .

zlib - , , , . win32. FAQ Windows:

http://www.zlib.net/DLL_FAQ.txt

7. Windows , , VB, , , .

, , . C VBA, , . VB-to-C - .

+3

VBA, ( VBA) , / VB, , . VB, . , VBA , " ", , , .

, gzip VBA .

: . , , .

Sub main()
    ActiveWorkbook.Save
    Open "macrotest.xls" For Binary Access Read As #1
    Open "newfile.zip" For Binary Access Write As #2
        'do your stuff here
    Close #2
    Close #1
End Sub
0

, , . VBA, GZipping , - , dll exe .

0

- , , COM-/DLL, Excel. - zip- Excel, , . , . ...

http://www.cpearson.com/excel/SaveCopyAndZip.htm

. COM "... , ( )". Moonlight Software, . , , GPL. Excel ( ).

- , , , Microsoft Windows Excel.

, .

0

All Articles