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
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