Solved

How to unzip a gz file with VBA

Posted on 2012-12-24
4
2,800 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 39

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 39

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 39

Accepted Solution

by:
als315 earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

785 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