Dim fso As Object
Dim objFolder As Object
Dim objFileList As Object
Dim vFile As Variant
Dim sFolder As String
sFolder = "C:\Docs"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(sFolder)
Set objFileList = objFolder.Files
For Each vFile In objFileList
' do something '
Next vFile
This code loops through all files in the C:\Docs folder. It creates a FileSystemObject and uses it to get a reference to the folder and its files. Then it iterates through each file object, allowing some action to be performed on each one.
This code loops through all files in the C:\Docs folder. It creates a FileSystemObject and uses it to get a reference to the folder and its files. Then it iterates through each file object, allowing some action to be performed on each one.
Dim fso As Object
Dim objFolder As Object
Dim objFileList As Object
Dim vFile As Variant
Dim sFolder As String
sFolder = "C:\Docs"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(sFolder)
Set objFileList = objFolder.Files
For Each vFile In objFileList
' do something '
Next vFile
This code loops through all files in the C:\Docs folder. It creates a FileSystemObject and uses it to get a reference to the folder and its files. Then it iterates through each file object, allowing some action to be performed on each one.
Dim objFileList As Object Dim vFile As Variant Dim sFolder As String sFolder = "C:\Docs" Set fso = CreateObject("Scripting.FileSystemObject") Set objFolder = fso.GetFolder(sFolder) Set objFileList = objFolder.Files For Each vFile In objFileList ' do something ' Next vFile