AOB
Registered User.
- Local time
- Today, 16:33
- Joined
- Sep 26, 2012
- Messages
- 617
Hi guys,
I'm trying to write a function to unzip a file (working off Ron de Bruin's code here)
The function should take the path of the zipped file as an argument and return the path of the unzipped file (extracting to the same folder)
But the code has no effect (i.e., I'm still left with just the zipped file in the folder, not the unzipped contents?)
There's no error captured so I don't know why this doesn't work? strFile is a legitimate path to an existing .zip file which contains a zipped .xls file
I debugged and put a watch on...
...but found that the .Count property was 0?
I've done several searches on how to unzip files using VBA and this seems to be the universally accepted method.
Can anybody help me figure out why it's not working for me?
Thanks
Al
I'm trying to write a function to unzip a file (working off Ron de Bruin's code here)
The function should take the path of the zipped file as an argument and return the path of the unzipped file (extracting to the same folder)
Code:
Public Function UnZipFile(strFile As String) As String
On Error GoTo ErrorHandler
Dim objFSO As Object
Dim objShellApp As Object
Dim strUnzipped As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")
With objFSO
objShellApp.Namespace(Replace(.GetAbsolutePathName(strFile), .GetFileName(strFile), "")).CopyHere _
objShellApp.Namespace(.GetAbsolutePathName(strFile)).Items
End With
Exit_UnZipFile:
Set objFSO = Nothing
Set objShellApp = Nothing
Exit Function
ErrorHandler:
Call LogError(Err.Number, Err.Description, "UnZipFile", "modImportFunctions")
Resume Exit_UnZipFile
End Function
But the code has no effect (i.e., I'm still left with just the zipped file in the folder, not the unzipped contents?)
There's no error captured so I don't know why this doesn't work? strFile is a legitimate path to an existing .zip file which contains a zipped .xls file
I debugged and put a watch on...
Code:
objShellApp.Namespace(.GetAbsolutePathName(strFile)).Items
...but found that the .Count property was 0?
I've done several searches on how to unzip files using VBA and this seems to be the universally accepted method.
Can anybody help me figure out why it's not working for me?
Thanks
Al