AW: *.bat
01.12.2019 19:44:54
Nepumuk
Hallo Sergej,
teste mal:
Option Explicit
Public Sub ReadTextfiles()
Const FILE_PATH_1 As String = "T:\Daten\2019\München\"
Const FILE_PATH_2 As String = "P:\Daten\2018\Berlin\"
Const FILE_PATH_3 As String = "S:\Kundendaten\2019\Hamburg\"
Const SEARCH_TEXT As String = "2019_PRJ = "
Const FOR_READING As Long = 1, TRISTATE_FALSE As Long = 0
Const TEXT_FILE As String = "Textdokument"
Dim vntPath As Variant, avntLines As Variant, vntLine As Variant
Dim lngRow As Long
Dim strText As String
Dim objFileSystemObject As Object, objFile As Object
Dim objFolder As Object, objTextStream As Object
Call Columns(1).ClearContents
Set objFileSystemObject = CreateObject(Class:="Scripting.FileSystemObject")
For Each vntPath In Array(FILE_PATH_1, FILE_PATH_2, FILE_PATH_3)
Set objFolder = objFileSystemObject.GetFolder(vntPath)
For Each objFile In objFolder.Files
If objFile.Type = TEXT_FILE Then
Set objTextStream = objFile.OpenAsTextStream(FOR_READING, TRISTATE_FALSE)
strText = objTextStream.ReadAll
objTextStream.Close
avntLines = Split(strText, vbCrLf)
For Each vntLine In avntLines
If Left$(vntLine, Len(SEARCH_TEXT)) = SEARCH_TEXT Then
lngRow = lngRow + 1
Cells(lngRow, 1).Value = Mid$(vntLine, Len(SEARCH_TEXT) + 1)
End If
Next
End If
Next
Next
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFileSystemObject = Nothing
End Sub
Gruß
Nepumuk