Link to home
Start Free TrialLog in
Avatar of TimHudspith
TimHudspith

asked on

How to unzip a gz file with VBA

How can I unzip a compressed file that has the extension '.gz' with VBA?
Avatar of als315
als315
Flag of Russian Federation image

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).
Avatar of TimHudspith
TimHudspith

ASKER

It doesn't work unfortunately. The code executes without error, but the destination directory remains empty.
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
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial