Consulting

Results 1 to 3 of 3

Thread: How to unzip with VBA?

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    33
    Location

    How to unzip with VBA?

    Hello experts,

    I just want to ask if you could help me in unzipping a zipped file or files with VBA. The zipped files contains excel files and they are located in a folder. The unzipped files should be in the same folder.

    Thanks in advance...

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello entwined,

    Here is a VBA version that works with Office 2007 and later. However, this macro can not unlock password protected Zip files.

    The macro will unzip and copy the files in the given folder from each Zip archive (*.zip) in the same folder. In the macro the folder is "C:\Test". Change this what you using.

    ' Written: March 15, 2017
    ' Author:  Leith Ross
    
    
    Sub UnZipFiles()
    
    
        Dim File        As Object
        Dim Files       As Object
        Dim MainFldr    As Object
        Dim MainPath    As Variant
        Dim oShell      As Object
        Dim ZipFile     As Variant
        Dim ZipFldr     As Object
        
            MainPath = "C:\Test"
            
            Set oShell = CreateObject("Shell.Application")
                
            Set MainFldr = oShell.Namespace(MainPath)
            
                Set Files = MainFldr.Items
                    Files.Filter 32, "*.zip"
                    
                For Each File In Files
                    Set ZipFldr = oShell.Namespace(File)
                    For Each ZipFile In ZipFldr.Items
                        MainFldr.CopyHere ZipFile.Path
                    Next ZipFile
                Next File
                
    End Sub
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •