קוד לייצוא שמות הקבצים מתוך תיקייה מסויימת (הקוד מייצא גם את נתיב הקובץ וגם את שם הקובץ)
שימו לב! כרגע היצוא הוא בשיטת debug יש להחליף לשיטת הייצוא הרצויה.
Sub FindFilesInDirectoryAndSubfoldersLateBound()
Dim fso As Object ' Declare fso as Object data type
Dim folderPath As String
Dim myFolder As Object ' Declare myFolder as Object data type
Dim subfolder As Object ' Declare subfolder as Object data type
Dim file As Object ' Declare file as Object data type
' Set the folder path where you want to search for files
folderPath = "C:\Users\0533105132\Documents\ToratEmetInstall\Books" ' Replace with the desired folder path
' Create a new late-bound FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check if the specified folder exists
If fso.FolderExists(folderPath) Then
' Get the Folder object for the specified folder
Set myFolder = fso.getfolder(folderPath)
' Call the recursive function to search files in the main folder and its subfolders
ProcessFolder myFolder
Else
' Folder does not exist
MsgBox "Folder not found: " & folderPath
End If
' Release the objects
Set file = Nothing
Set subfolder = Nothing
Set myFolder = Nothing
Set fso = Nothing
End Sub
Sub ProcessFolder(ByVal folder As Object)
Dim myfile As Object
Dim subfolder As Object
' Process files in the current folder
For Each myfile In folder.Files
' Print the file name (you can perform any desired action here)
Debug.Print myfile.Path
Debug.Print myfile.Name
Next myfile
' Recursively process subfolders
For Each subfolder In folder.Subfolders
ProcessFolder subfolder
Next subfolder
End Sub