AW: Import Strukturierter Text
10.04.2006 11:03:23
ede
hallo nochmal,
dann teste mal den nachstehenden code!
rückantwort wäre super!
gruss
Sub Text_Import()
Dim spalte As Integer
Dim zeile As Integer
Dim startpos As Integer
'StartVerzeichnis - bitte anpassen
ChDrive "c:\"
ChDir "\temp"
'Dialogfenster Öffnen
sFile = Application.GetOpenFilename _
("alle Dateien (*.txt), *.txt")
If sFile <> False Then
Close
Open sFile For Input As #1
zeile = 2
Cells(1, 1).Value = "Name"
Cells(1, 2).Value = "Vorname"
Cells(1, 3).Value = "Wohnort"
Do While Not EOF(1)
Line Input #1, strtxt
spalte = 0
If UCase(Left(strtxt, 4)) = UCase("Name") Then
spalte = 1
startpos = 8
End If
If UCase(Left(strtxt, 7)) = UCase("Vorname") Then
spalte = 2
startpos = 10
End If
If UCase(Left(strtxt, 7)) = UCase("Wohnort") Then
spalte = 3
startpos = 10
End If
If spalte > 0 Then Cells(zeile, spalte).Value = Mid(strtxt, startpos)
If strtxt = "" Then zeile = zeile + 1
Loop
Close
End If
End Sub