Question : VBA Unzipping a file

Hi,

I found some code from http://www.rondebruin.nl/windowsxpunzip.htm about to unzip a file using VBA. The problem is with my code is that it debugs at the line "oAPP.Namespace(FileNameFolder).CopyHere oAPP.Namespace(Fname).Items". The message is object variable or with with block not set.

The code is as below & as always any help would be great!

Thanks
Mark

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Sub UnzIpp()

'Unzip JPM Files
Dim FSO As Object
Dim oAPP As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
 
'JPM_File = ("G:\Shared\High Yield\Chris\Daily Performance\Daily JPM Prices\Valuation Summary")

Fname = "G:\Shared\High Yield\Chris\Daily Performance\Daily JPM Prices\Valuation Summary_20100823.zip"

FileNameFolder = "G:\Shared\High Yield\Chris\Daily Performance\Daily JPM Prices\Unzipped\Valuation Summary_20100823.xls"

Set oAPP = CreateObject("Shell.Application")
    oAPP.Namespace(FileNameFolder).CopyHere oAPP.Namespace(Fname).Items

      On Error Resume Next
        Set FSO = CreateObject("scripting.filesystemobject")
        FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True

    Set wbTemp = Workbooks.Open(JPM_File)
    wbTemp.SaveAs ("G:\Shared\High Yield\Chris\Daily Performance\Daily JPM Prices\Unzipped\Valuation Summary_20100823.xls")
    'wbTemp = JPM_File

End Sub

Answer : VBA Unzipping a file

Ok, well there does seem to be something weird going on here. Look at this:

http://www.codeguru.com/forum/showthread.php?t=443782

You might also try:

oAPP.Namespace((FileNameFolder)).CopyHere oAPP.Namespace((Fname)).Items

Other than this, the question comes down to "which object is not created?" There are two candidates for this: either oAPP is not set, which I would say is unlikely, or the Namespace(FileNameFolder) object is not set. You can find out which using the IDE at the point the code stops.

I would urge you to look *very* closely at those file paths - are you sure they're exactly the same? A digit out of order? An underscore where it shouldn't be?

Copy the zip file path from your code, i.e.

G:\Shared\High Yield\Chris\Daily Performance\Daily JPM Prices\Valuation Summary_20100823.zip

and paste it into the address bar of explorer - it should open the zip file if the path is correct.

If none of these work I would try fiddling around with variations based on the link at the start of this email. *Try defining your filepaths as Strings instead of Variants (you should probably do this anyway), and then try the variations on the link, etc.
*Try abandoning the variables completely and just pass the hardcoded paths to Namespace().
*Try specifying the paths using UNC instead of drive mapping (i.e. \\<server>\<share>\Shared\High Yield\Chris\Daily Performance... etc.)

If the problem is indeed to do with the Namespace object, you may have to get creative to solve it.
Random Solutions  
 
programming4us programming4us