Stop searching. Start learning and developing your excel skills.
Macro
VBA
Formula
Function
Shortcut
Tricks

» » VBA To Unzip A File or Folder

VBA To Unzip A File or Folder

June 02, 2017 |
This is also related to below queries:
  1. vba unzip multiple files
  2. excel vba zip multiple files
  3. extract zip file using excel vba
  4. macro to unzip all files in a folder
The Codes:
Function entUnZip1File(ByVal strZipFilename, ByVal strDstDir, ByVal strFilename)
  Const glngcCopyHereDisplayProgressBox = 256

  Dim intOptions, objShell, objSource, objTarget

  Set objShell = CreateObject("Shell.Application")
  Set objSource = objShell.Namespace(strZipFilename).Items.Item(CStr(strFilename))
  Set objTarget = objShell.Namespace(strDstDir)

  intOptions = glngcCopyHereDisplayProgressBox
  objTarget.CopyHere objSource, intOptions

  Set objSource = Nothing
  Set objTarget = Nothing
  Set objShell = Nothing
  entUnZip1File = 1
End Function

Sub
entUnZip1File "PermanentDirectoryOfZippedFile" & VariableZippedFolderName & ".zip", "DirectoryToSaveExtractionFile", "FileNameToExtract.dat"

''' repeat this code if you have many files

end Sub

Note:
  1. The zipped file is located in PermanentDirectoryOfZippedFile\VariableZippedFolderName. For example C:\Users\YourUserName\Desktop\2017-06-01 where C:\Users\YourUserName\Desktop is permanent path and 2017-06-01 is variable folder with daily changes
  2. The zipped file name is FileNameToExtract.dat
  3. Location that you want to save unzipped or extracted file is DirectoryToSaveExtractionFile
Steps:
  1. Replace the text highlighted in yellow with your needs
  2. Done

No comments:

Post a Comment