What is the proper Zip format for xlsx

Tegron1
Tegron1 used Ask the Experts™
on
I am attempting to create an xlsm file programmatically, but I seem to be getting the Zip encoding incorrect.  My process is:
1 - create a file in Excel
2 - save the file as xlsx (or m)
3 - unzip the file
4 - make a copy of the unzipped directory
5 - Send To -> Compressed (zipped) Folder

When I open it in Excel, it says "Excel found unreadable content in 'file.xlsx.'...". and it is unable to read the file.

I have also tried using the RAR encoder to generate a zip file, but that does not work either.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008
Commented:
Yep, that's a little tricky. Create the zip file using this code:

Public Sub CreateZIPFile( _
        ByVal sFilePath As String _
    )
   
' Create a new ZIP file.

    If Len(Dir(sFilePath)) > 0 Then Kill sFilePath
    Open sFilePath For Output As #1
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1

End Sub

Once you've done that then you can copy files to it using regular file copy functions.

Kevin

Author

Commented:
awesome!  that appears to work.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial