Gruppe
Allgemein
Problem
Wie kann ich eine Datei in einem Verzeichnis unter Einbeziehung der Unterverzeichnisse suchen?
StandardModule: basMain
Sub Suchen()
Dim fs As FileSearch
Dim sDir As String, sFile As String
sDir = InputBox( _
prompt:="Verzeichnis:", _
Default:=Application.DefaultFilePath)
If sDir = "" Then Exit Sub
sFile = InputBox( _
prompt:="Dateiname:", _
Default:="test1.xls")
If sFile = "" Then Exit Sub
Set fs = Application.FileSearch
With fs
.LookIn = sDir
.SearchSubFolders = True
.FileName = sFile
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "Gefunden: " & .FoundFiles(1)
Else
MsgBox "Datei wurde nicht gefunden!"
End If
End With
End Sub