Sub test()
Dim myDir As String, fn As String, myList, i As Long, ii As Long, iii As Long
Dim a, b, x, y, e, n As Long, temp(), txt As String, flg As Boolean
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then myDir = .SelectedItems(1) & "\"
End With
If myDir = "" Then Exit Sub
myList = SearchFiles(myDir, Array("txt", "cfg"), 0, temp(), 1)
If IsError(myList) Then MsgBox "No file": Exit Sub
a = Sheets("tabelle1").Cells(1).CurrentRegion.Value
ReDim b(1 To 50000, 1 To 3)
For i = 1 To UBound(myList, 2)
fn = myList(1, i) & "\" & myList(2, i)
If FileLen(fn) Then
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
For Each e In Array(vbCrLf, vbCr, vbLf)
If InStr(txt, e) Then x = Split(txt, e): Exit For
Next
If IsArray(x) Then
For ii = 1 To 3
For iii = 3 To UBound(a, 1)
If a(iii, ii) <> "" Then
y = Filter(x, a(iii, ii), 1)
If UBound(y) > -1 Then
If Not flg Then n = n + 1: flg = True
b(n, ii) = b(n, ii) & IIf(b(n, ii) <> "", "; ", "") & y(0)
End If
End If
Next iii, ii
x = Empty: flg = False
End If
x = Empty
End If
Next
Sheets.Add.Cells(1).CurrentRegion.Resize(n, 3) = b
End Sub
Private Function SearchFiles(myDir As String, Ext, n As Long, myList(), _
Optional SearchSub As Boolean = False) As Variant
Dim FSO As Object, myFolder As Object, myFile As Object, e, flg As Boolean
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each myFile In FSO.GetFolder(myDir).Files
Select Case myFile.Attributes
Case 2, 4, 6, 34
Case Else
If Not myFile.Name Like "~$*" Then
If IsArray(Ext) Then
For Each e In Ext
If UCase$(myFile.Name) Like UCase$("*" & e) Then
flg = True: Exit For
End If
Next
Else
flg = UCase$(myFile.Name) Like UCase$("*" & Ext)
End If
If flg Then
n = n + 1
ReDim Preserve myList(1 To 2, 1 To n)
myList(1, n) = myDir
myList(2, n) = myFile.Name
End If
End If
End Select
Next
If SearchSub Then
For Each myFolder In FSO.GetFolder(myDir).SubFolders
SearchFiles = SearchFiles(myFolder.Path, Ext, _
n, myList, SearchSub)
Next
End If
SearchFiles = IIf(n > 0, myList, CVErr(xlErrRef))
End Function
Bookmarks