Article ID: 165643
Article Last Modified on 1/19/2007
Sub GetFileList()
Dim oSearch As FileSearch
' Change strDirName to the path of the directory for which you want a
' listing.
Dim strDirName As String: strDirName = CurDir()
Dim strPrompt As String: strPrompt = strDirName & Chr(13) & Chr(13)
Dim i As Long
' Get a reference to the FileSearch object.
Set oSearch = Application.FileSearch
With oSearch
' Reset the search.
.NewSearch
' Specify the directory that contains the files you want to count.
' The variable strDirName is the parameter of the CountAllFiles()
' function.
.LookIn = strDirName
' Exclude subfolders.
.SearchSubFolders = False
' Specify what types of files you want to find.
' For example, to search for text files change this line to:
' .FileName "*.txt"
.FileName = "*.*"
' The Execute command begins the search.
.Execute
' Check to see if any files were found.
If .FoundFiles.Count > 0 Then
' Loop through the files that were found and store the file names
' in the variable strPrompt.
For i = 1 To .FoundFiles.Count
strPrompt = strPrompt & .FoundFiles(i) & Chr(13)
Next i
Else
strPrompt = strPrompt & "No files found."
End If
' Display the file list in a message box.
MsgBox strPrompt
End With
End Sub
Additional query words: wordcon 8.00 kbmacro ppt8 vba vbe ppt97
Keywords: kbhowto kbprogramming KB165643