objeto requerido erro vba

0
 Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objSubFolder As Object
    Dim fil As File

    With Application.FileDialog(msoFileDialogFolderPicker) 'Choosing FromPath
        .Show
        FromPath = .SelectedItems(1) & "\"
    End With

    With Application.FileDialog(msoFileDialogFolderPicker) 'Choosing ToPath
        .Show
        ToPath = .SelectedItems(1) & "\"
    End With


   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFolder = objFSO.GetFolder(FromPath)
   For Each objSubFolder In objFolder.SubFolders
        **Set fils = fsoC.GetFolder(objSubFolder & "\").Files**

        For Each fil In fils
            If LCase(Right(fil.Name, 3)) = "zip" Then
               MsgBox "this is a zip file "
            Else

Estou recebendo um erro de objeto solicitado na linha marcada e não entendo por quê? Alguém pode me ajudar por favor?

    
por netanel 06.09.2016 / 07:57

1 resposta

0

fsoC parece não ser declarado / instanciado no seu script. Talvez você gostaria de usar objFSO novamente?

Editar:

Sub test()
 Dim fils As Object
 Dim fil As Object
 Dim FromPath As String
 Dim ToPath As String
 Dim objFSO As Object
 Dim objFolder As Object
 Dim objSubFolder As Object

 With Application.FileDialog(msoFileDialogFolderPicker) 'Choosing FromPath
     .Show
     FromPath = .SelectedItems(1) & "\"
 End With

 With Application.FileDialog(msoFileDialogFolderPicker) 'Choosing ToPath
     .Show
     ToPath = .SelectedItems(1) & "\"
 End With


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FromPath)
For Each objSubFolder In objFolder.SubFolders
   Set fils = objFSO.GetFolder(objSubFolder & "\").Files

   For Each fil In fils
      If LCase(Right(fil.Name, 3)) = "zip" Then
         MsgBox "this is a zip file "
      Else
         MsgBox "NOPE"
      End If
    Next
Next
End Sub

Este código funciona com a seguinte pasta:

A
-- A.1
---- test.txt
---- test.zip
    
por 06.09.2016 / 08:26