Solved

How to unzip a gz file with VBA

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now