Wie importiere ich bestimmten Text aus Dateien in Excel?

Ich habe diesen Code von @Scott Holtzman gefunden und ich muss ihn ein wenig pendeln, um meinen Anforderungen zu entsprechen. Dieser Code nimmt jede Zeile in einer Textdatei und fügt sie in separate Spalten in einem Excel-Arbeitsblatt ein (A1, B1, C1 usw.). Jede Textdatei wird in einer separaten Zeile gespeichert (1,2,3 usw.). Erstens möchte ich, dass Text nur dann in das Excel-Arbeitsblatt eingefügt wird, wenn die Zeile mit einem bestimmten Text beginnt, zweitens möchte ich, dass nur ein Teil des Texts aus jeder Zeile in das Excel-Arbeitsblatt kopiert wird.

Sub ReadFilesIntoActiveSheet()

Dim fso As FileSystemObject
Dim folder As folder, file As file, FileText As TextStream
Dim TextLine As String, Items() As String
Dim i As Long, cl As Range

' Get a FileSystem object
Set fso = New FileSystemObject

' get the directory you want
Set folder = fso.GetFolder("D:\YourDirectory\")

Dim x As Long
x = 1 'to offset rows for each file

' Loop thru all files in the folder
For Each file In folder.Files

' set the starting point to write the data to
Set cl = ActiveSheet.Cells(x, 1)

' Open the file
Set FileText = file.OpenAsTextStream(ForReading)

Dim j As Long
j = 0 'to offset columsn for each line
' Read the file one line at a time
Do While Not FileText.AtEndOfStream

    TextLine = FileText.ReadLine 'read line

    cl.Offset(, j).Value = TextLine 'fill cell

    j = j + 1
Loop

' Clean up
FileText.Close

x = x + 1

Next file

Set FileText = Nothing
Set file = Nothing
Set folder = Nothing
Set fso = Nothing

End Sub

Hier sehen meine Textdateien aus:

From:NameName           'want all text except the "FROM:"
Date:yyyy.mm.dd         'want all text except the "Date:"
Type: XXXXXXXXX         ' I don't want this line into excel
To: namename            ' I don't want this line into excel

----------------------------- xxxxxxx ---------------------
A1: Tnr xxxxxxxxxxxxx   'want all text except the "A1: Tnr" only next 13char
A2: texttext            'want all text except the "A2:"
An:                     'A1 and up to A14
A14: texttext           'want all text except the "A14:"  

------------------------------ xxxxxx ----------------------

Die Textdatei enthält insgesamt 22 Zeilen.

Und wenn es möglich ist, FROM :, DATE :, A1: bis A14: als Überschriften in der ersten Zeile zu verwenden, wäre das episch.

habe versucht, meinen Weg dahin zu googeln, und ein bisschen damit versucht:

TextLine =    FileText.ReadLine 'read line
If InStr(TextLine, "A1:") 

Aber das funktioniert nur für eine Zeile und ich kann nicht scheinen, es mit mehreren Zeilen zum Laufen zu bringen. Außerdem wird die Ausgabe in Zelle F1 anstelle von A1 abgelegt. denke, das liegt daran, dass jede Zeile im Textdokument eine Zelle erhält - auch wenn nichts darauf geschrieben ist.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage