msgbox all file in folder

Public Sub DisplayTextFileNames()
Dim fso As Object
Dim folder As Object
Dim file As Object
Dim folderPath As String

' Specify the path to your directory
folderPath = "C:\path\to\your\directory"

' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

' Get the folder
Set folder = fso.GetFolder(folderPath)

' Iterate through each file in the folder
For Each file In folder.Files
    ' Check if the file is a text file
    If LCase(fso.GetExtensionName(file.Name)) = "txt" Then
        ' Display a message box with the file name
        MsgBox file.Name
    End If
Next file

' Clean up
Set file = Nothing
Set folder = Nothing
Set fso = Nothing

End Sub

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *