Saturday, October 8, 2016

VBA code to unzip files from multiple zip files!!!

Unzip files is one of the regular task in our daily activity. Thus, most of us often prefer zip files to publish our data to end users. As, we know zip files are extensively use to compress files and folder which can be easily shared with business owners. Sometimes, we need to work with multiple zip file simultaneously and we need to unzip multiple files. Therefore, it takes lot of time to unzip multiple zip files for that instance. However, using excel macro this task can be automated. let's see how can we use excel macro to unzip multiple zip files on a single go.












Here is the code to unzip multiple zip files:

Sub Unzip_Files()
' Author: Dreams24
' Written for VBA Tricks and tips blog
' https://www.vbatricksntips.com

'Declare Variable
    Dim oApp As Object
    Dim Fname As Variant
    Dim Output_Folder As Variant
    Dim strDate As String
    Dim i As Long
   
    'Select multiple zip files to unzip
    Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
                                        MultiSelect:=True)
    If IsArray(Fname) = False Then
        'Do nothing
    Else
        
        'Set output folder path for unzip files
        Output_Folder = "C:\Users\Dreams\Desktop\Test_Unzip\Unzip"
        
        'Append backslash to output folder path
        If Right(Output_Folder, 1) <> "\" Then
            Output_Folder = Output_Folder & "\"
        End If

        'Extract the files into output folder
        Set oApp = CreateObject("Shell.Application")
        For i = LBound(Fname) To UBound(Fname)
            
            oApp.Namespace(Output_Folder).CopyHere oApp.Namespace(Fname(i)).items

        Next i

        MsgBox "You find the files here: " & Output_Folder
        
    End If
    
End Sub

No comments: