Monday, February 8, 2016

VBA code for unzip the files (multiple files can be selected)

Option Explicit
Sub Unzip_Files()
  Dim fCounter As Integer
  Dim UzipFolderPath As String
  Dim oApp As Object

With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = True
    .Filters.Add "Zip Files", "*.zip"
    .Title = "please select zip files"
    .Show
    If .SelectedItems.Count = 0 Then
        MsgBox "file not selected", vbOKOnly + vbInformation, "Task Cancelled"
        Exit Sub
    Else
        'Extract the files into the newly created folder
        Set oApp = CreateObject("Shell.Application")
     
        UzipFolderPath = CurrentProject.Path & "\UnZippedFiles"
        MkDir UzipFolderPath
        For fCounter = 1 To .SelectedItems.Count
            oApp.Namespace(UzipFolderPath & "\").CopyHere oApp.Namespace(.SelectedItems(fCounter)).items
        Next
    End If
End With
    Set oApp = Nothing
End Sub

'************************************************************************
'check this out and let me if it works.
Note: The above code has been written in msaccess
So, if you want to run this in excel. change the above syntax:
* CurrentProject.Path to thisworkbook.path

No comments:

Post a Comment

Excel VBA to send email from excel with HTML table in a email body

'' Excel vba script to send email from outlook & email body in HTML table format. ''Write down email body in HTML tags...