Gruppe
Extern
Problem
Alle Textdateien eines Verzeichnisses sollen nach einem Suchbegriff durchsucht und die Fundzeilen in diese Tabelle eingetragen werden.
StandardModule: Modul1
Sub GrepText()
Dim fs As FileSearch
Dim lRow As Long, lFile As Long
Dim iCounter As Integer
Dim sDir As String, sTxt As String, sBegriff As String
Application.ScreenUpdating = False
sDir = Range("H1").Value
sBegriff = Range("H3").Value
Columns("A").ClearContents
Set fs = Application.FileSearch
With fs
.LookIn = sDir
.Filename = Range("H2").Value
.Execute
For iCounter = 1 To .FoundFiles.Count
lFile = lFile + 1
If lFile Mod 100 = 0 Then Application.StatusBar = _
"Bearbeite Datei " & lFile & "..."
Open .FoundFiles(iCounter) For Input As #1
Do Until EOF(1)
Line Input #1, sTxt
If InStr(sTxt, sBegriff) Then
lRow = lRow + 1
Cells(lRow, 1).Value = sTxt
End If
Loop
Close
Next iCounter
End With
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub