Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to unzip a gz file with VBA

Posted on 2012-12-24
4
Medium Priority
?
3,426 Views
Last Modified: 2012-12-25
How can I unzip a compressed file that has the extension '.gz' with VBA?
0
Comment
Question by:TimHudspith
  • 3
4 Comments
 
LVL 40

Expert Comment

by:als315
ID: 38719745
You can install free 7zip archiver (http://www.7-zip.org/) and use shell:
MyFile = "c:\files\test.gz"
Outdir = "c:\out"
Call Shell("c:\Program Files\7-Zip\7z.exe e " & MyFiel & "-o" & Outdir, 1)
Correct path to 7z.exe (you can place it everywhere).
0
 

Author Comment

by:TimHudspith
ID: 38719760
It doesn't work unfortunately. The code executes without error, but the destination directory remains empty.
0
 
LVL 40

Expert Comment

by:als315
ID: 38719905
Try to add quotes before and after path:
MyFile = chr(34) & "c:\files\test.gz" & chr(34)
Outdir = chr(34) & "c:\out" & chr(34)
Cmdstr = "c:\Program Files\7-Zip\7z.exe e " & MyFile & "-o" & Outdir
debug.print CmdStr
Call Shell(Cmdstr,1)
You can test resulting string from command prompt
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 38719919
Sorry, one space was omitted:
Sub tst()
Dim MyFile As String, Outdir As String, Cmdstr As String
MyFile = Chr(34) & "c:\TMP\ratings.gz" & Chr(34)
Outdir = Chr(34) & "c:\tmp\0" & Chr(34)
Cmdstr = "c:\Program Files\7-Zip\7z.exe" & " e " & MyFile & " -o" & Outdir
Debug.Print Cmdstr
Call Shell(Cmdstr, 1)
End Sub

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question