Objekt benötigt Fehler vba - Microsoft-Excel, vba

 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

Ich erhalte in der markierten Zeile den Fehler "Objekt erforderlich" und verstehe nicht warum? Kann mir jemand bitte helfen?

Antworten:

0 fĂĽr Antwort â„– 1

fsoC scheint in Ihrem Skript nicht deklariert / instanziiert zu sein. Vielleicht möchten Sie verwenden objFSO nochmal ?

Bearbeiten:

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

Dieser Code funktioniert mit dem folgenden Ordner:

A
-- A.1
---- test.txt
---- test.zip

Lies jetzt