Error 91 when using CopyHere to extract a zipped file

fwjcloud

New Member
Joined
Jun 23, 2009
Messages
23
I have a piece of code that creates a list of files in a folder. I then loop through the list and take different actions depending on the file type. One action is to extract a csv file from a zipped file. I then have a sub procedure to do the extracting if for each .csv file in the zipped on but I get an 'Run-Time Error 91 Object varible or with block variable not set' when it tries to copy the extracted file to another folder. I know the folder exists because I test that earlier in the code. Can anyone help?

My main code is like this

If fs.folderexists(inFolder) = True Then
Set fdList = fs.getfolder(inFolder) 'Folder List
Set flList = fdList.Files 'File List

For Each iFile In flList

If LCase(Mid(iFile.Name, Len(iFile.Name) - 3, 4)) = ".zip" Then
'Unzip file
Unzip_File iFile.Name, inFolder, outFolder
ElseIf
'
End If
Next iFile
End If

My sub procedure is

Sub Unzip_File(fName As Variant, iFolder As Variant, oFolder As Variant)
Dim fileNameInZip As Variant

Set oApp = CreateObject("Shell.application")
For Each fileNameInZip In oApp.Namespace(iFolder & fName).items
If LCase(fileNameInZip) Like LCase("*.csv") Then
oApp.Namespace(oFolder).CopyHere oApp.Namespace(iFolder & fName).items.Item(CStr(fileNameInZip)) <<- Fails here
End If
Next

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I found a solution myself

I replaced the failed line with
oApp.Namespace(oFolder).CopHere o.App.Namespace(CStr(iFolder & fName)).items.Item(CStr(fileNameInZip))
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top