Unzip all archives from a folder

Tested in Excel 365 (16.8730.2046) 64-bit. All links open in new tab.

Note: This macro doesn’t go through sub-folders. It s similar to using IzArc: select all files and right-click => Extract here… or Extract each archive in separate folder…

 
 
  1. Public Sub UnZipAll()
  2. Dim MyFile As String, MyFolder As String, DestinationFolder As String
  3. 'the folder where zip file is
  4. MyFolder = PickFileOrFolder(0)
  5. 'Loop through all zip files in a given directory
  6. MyFile = Dir(MyFolder & "\*.zip")
  7. Do While Len(MyFile) > 0
  8.     Call UnzipIt(MyFolder & "\" & MyFile, 0)
  9.     Debug.Print MyFile
  10.     MyFile = Dir
  11. Loop
  12. End Sub
  13. '
  14. Public Sub UnzipIt(ZipFile As String, Optional NewPath As Boolean = False)
  15.     Dim oApp As Object
  16.     Dim FileName, FilePath, NewFilePath
  17.    
  18.     FileName = ZipFile
  19.     If NewPath Then
  20.         'optional, extract to a subfolder having the same name as the file
  21.        FilePath = Left(FileName, Len(FileName) - 4) & "\"
  22.         MkDir FilePath
  23.     Else
  24.         FilePath = Left(FileName, InStrRev(FileName, "\"))
  25.     End If
  26.    
  27.     If FileName <> "" Then
  28.         'Extract the files into the selected folder
  29.        Set oApp = CreateObject("Shell.Application")
  30.         oApp.Namespace(FilePath).CopyHere oApp.Namespace(FileName).items
  31.     End If
  32. End Sub

PickFileOrFolder function is here

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.