![]() 'Use For Each loop to loop through each file in the folder For Each FSOFile In FSOFile Set FSOFolder = FSOLibrary.GetFolder(folderName) 'Set all the references to the FSO Library Set FSOLibrary = CreateObject("Scripting.FileSystemObject") For example: 'Loop through each file with an extension of ".xlsx"įileName = Dir("C:\Users\marks\Documents\*.xlsx") 'Loop through each file containing the word "January" in the filenameįileName = Dir("C:\Users\marks\Documents\*January*") 'Loop through each text file in a folderįileName = Dir("C:\Users\marks\Documents\*.txt") Using the File System Object (FSO) Late Binding – Method #2 Sub LoopAllFilesInFolder()ĭim folderName As String Dim FSOLibrary As Object Dim FSOFolder As Object Dim FSOFile As Object 'Set the file name to a variable Vb6 open any file code#The code above can easily be adapted with the use of wildcard characters. 'Insert the actions to be performed on each file 'This example will print the file name to the immediate window ![]() 'Loop through all files in a folder Dim fileName As VariantįileName = Dir("C:\Users\marks\Documents\") Using the Dir Function – Method #1 Sub LoopAllFilesInAFolder() Check out the other VBA Code Snippets to see what else could be achieved. ![]() But it is easy enough to change the code to make it more complex and fit with your specific circumstances. The example we are looking will print the file name to the immediate window. Looping through all the files in a folder
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |