Unzip files in folder and subfolders
This vba macro lets you search for zip files in a folder. Then unzip those files to a folder you specify. It continues with sub folders until all zip files have been unzipped.
What happens when you execute the macro?
- Select a folder you want to search.
- Select a destination folder. This is where all unzipped files will be copied to.
- Macro unzips all zip files in folder and sub folders.
- Macro ends.

VBA Code
Actually there are two macros. Run UnzipFiles to start unzipping files.
Sub UnzipFiles() Dim myfolder Dim destfolder With Application.FileDialog(msoFileDialogFolderPicker) .Show myfolder = .SelectedItems(1) & "\" End With With Application.FileDialog(msoFileDialogFolderPicker) .Show destfolder = .SelectedItems(1) & "\" End With Call Recursive(myfolder, destfolder) End Sub
Sub Recursive(FolderPath As Variant, destfolder As Variant) Dim Value As String, Folders() As String Dim Folder As Variant, a As Long Dim SApp As Object ReDim Folders(0) If Right(FolderPath, 2) = "\\" Then Exit Sub Value = Dir(FolderPath, &H1F) Do Until Value = "" If Value = "." Or Value = ".." Then Else If GetAttr(FolderPath & Value) = 16 Or GetAttr(FolderPath & Value) = 48 Then Folders(UBound(Folders)) = Value ReDim Preserve Folders(UBound(Folders) + 1) Else If Right(Value, 4) = ".zip" Then Set SApp = CreateObject("Shell.Application") SApp.Namespace(destfolder).CopyHere _ SApp.Namespace(FolderPath & Value).items End If End If End If Value = Dir Loop For Each Folder In Folders Call Recursive(FolderPath & Folder & "\", destfolder) Next Folder End Sub
Download excel *.xlsm file
Search all workbooks in a folder
Today I'll show you how to search all Excel workbooks with file extensions xls, xlsx and xlsm in a given folder for a […]
Open Excel files in a folder [VBA]
This tutorial shows you how to list excel files in a specific folder and create adjacent checkboxes, using VBA. The […]
What's on this page Copy a file Copy and rename a file Rename a file List files in a folder […]
Search all workbooks in a folder and sub folders
Search all workbooks in a folder is a popular post, I am happy so many find it useful. rusl cato […]
List files in a folder and subfolders [UDF]
This article demonstrates a user defined function that lists files in a ggiven folder and subfolders. A user defined function is […]
Search for a file in folder and subfolders [UDF]
The image above demonstrates a user-defined function in cell range B6:D7 that allows you to search a folder and subfolders […]
Compare file names in two different folder locations and their sub folders
Today I would like to share a macro that compares the content in two different folders and their sub folders. […]
Find and replace a text string in file names, folder name and subfolders
The following two macros lets you rename files and folders recursively. Press Alt + F8 to open a list of macros, run […]
Which Excel files in folder are password protected?
This article explains how to check if Excel files in a given folder are password protected. The image above shows […]
Macros are great for doing repetitive tasks. Two years ago I wrote a post about transferring data to worksheets. It is […]
2 Responses to “Unzip files in folder and subfolders”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Dear Sir
I have a zip file in D:\ , which I want to unzip so used the code to unzip the file(file is csv format).
The macro searches the folder and shows no files to unzip.
However there are two files to unzip which the macro is unable to detect
Please help.
Thank you very much for sharing your codes.