PDA

View Full Version : [SOLVED:] Unzip files to a folder udf



YasserKhalil
08-22-2017, 11:04 AM
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?

mdmackillop
08-22-2017, 12:15 PM
Hi Yasser

Dim strPath As Variant

YasserKhalil
08-22-2017, 12:51 PM
Thank you very much MD
That's awesome but why As Variant while strPath line considered as String??!

mdmackillop
08-22-2017, 01:39 PM
The second sub needs a Variant (Ron de Bruin) and you are passing a String