Consulting

Results 1 to 4 of 4

Thread: Unzip files to a folder udf

  1. #1

    Unzip files to a folder udf

    Hello everyone
    I have this code that is supposed to unzip files
    Sub Test_UnZipFile()
        Dim strPath As String
    
    
        strPath = ThisWorkbook.Path & "\TestFolder\"
        If Len(Dir(strPath, vbDirectory)) = 0 Then MkDir strPath
        
        Call UnZipFile(ThisWorkbook.Path & "\TestFolderZipped.zip", strPath)
        MsgBox "Done...", 64
    End Sub
    
    
    Sub UnZipFile(zippedFileFullName As Variant, unzipToPath As Variant)
        Dim shellApp As Object
    
    
        Set shellApp = CreateObject("Shell.Application")
        shellApp.Namespace(unzipToPath).CopyHere shellApp.Namespace(zippedFileFullName).items
    End Sub
    But I encountered an error Runtime error '91'

    Any help how to fix this UDF?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Yasser
    Dim strPath As Variant
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thank you very much MD
    That's awesome but why As Variant while strPath line considered as String??!

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The second sub needs a Variant (Ron de Bruin) and you are passing a String
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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