Here is a simple code for you, this function list files in a folder on an Excel sheet. Note that if there are sub-folders available in the folder then this function will not read the files inside the sub-folders.
'This function lists files in a folder
'Note: It will not read any files inside a sub-folder
Public Sub ListFilesInFolder()
'Variable Declaration
Dim strPath As String
Dim vFile As Variant
Dim iCurRow As Integer
'Clear old data
Sheet1.Range("B9:B1000").ClearContents
'Set the path of the folder
strPath = Sheet1.Range("B4").Value
'Add slash at the end of the path
If Right(strPath, 1) <> "/" And Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
'Set Directory to folder path
ChDir strPath
vFile = Dir(strPath & "*.*") 'Change or add formats to get specific file types
iCurRow = 9
Do While vFile <> "" 'LOOP until all files in folder strPath have been looped through
Sheet1.Cells(iCurRow, 2).Value = vFile
vFile = Dir
iCurRow = iCurRow + 1
Loop
End Sub
To use this code in your Excel file, follow below steps:
1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from the menu bar
4. Paste the code in the module
5. Now add a shape to the Excel sheet
6. Give a name to the shape like ‘List Files in Folder’
7. Right-click on the shape and select ‘Assign Macro…’
8. Select ‘ListFilesInFolder’ from the list and click on ‘Ok’ button
9. Done, enter a folder path in cell B4 and click on the ‘List Files in Folder’ button
Excel Files and Sheets Consolidator is an MS Excel based data consolidation tool which can be used to consolidate data from multiple Excel Files or Excel Sheets. The tool supports multiple configurations such as Sheet Name, Sheet Index, Header Row and Non-Blank column to help consolidating accurate data.
How to Find Duplicate Files In excel using VBA? Yesterday I was working on my computer and cleaning the drives to make some more space. I was surprised to see so many files saved at…
To ensure that your VBA project works smoothly without any error, you need to put lot of error handlers and validations. Here is one of them, below code can be used to check if the given path is valid or not. You just need to provide the path of the file to the function and it will check if the file exist at the location. If it returns True that means the file is available at the path, if it returns False that means it is invalid path or the file does not exist at the location.
File Properties Tool is an MS Excel based tool which helps you to get File Name, File Path, Date Created, Date Last Accessed, Date Last Modified, Size (MB) and File Type properties of the files. You just need to browse the folder where your files are and click on ‘Get File Properties’ button.
This Excel VBA Code converts the excel range into HTML and also can convert Excel to HTML Table to paste data on Outlook Email Body
Free File Renamer Tool – Quickly Rename files batch using Excel VBA Here is another help code and tool for programmers to rename files. You can use this tool for renaming all files available in…
great help and . nicely presented