Das Archiv des Excel-Forums
nochmal txt.Import
Betrifft: nochmal txt.Import
von: Heiko F.
Geschrieben am: 02.10.2003 17:06:04
Hallo nochmal an alle ,
hatte vor 2 Stunden schon die Frage gestellt und eine super Lösung bekommen
(Reinhardt und Hans ).-- DANKE!
Nun eine andere Frage. Mit dem Modul wird die txt datei ausgelesen und eingefügt.
Ich möchte nun das Modul in einer Art Mustermappe abspeichern und die txt .Datei
soll in eine vorhenden xls Datei KBR01.xls kopiert werden.
Könnt ihr mir nochmal helfen ?
Sub TextImport()
Dim arr As Variant
Dim iRow As Integer, iCounter As Integer
Dim sFile As String, sTxt As String
sFile = Range("P1").Value
If Dir(sFile) = "" Then
Beep
MsgBox "Datei wurde nicht gefunden!"
Exit Sub
End If
iRow = 9
Close
Open sFile For Input As #1
icol = 6 'F-Spalte
iRow = 9
For n = 1 To 6 'ersten 6 Zeilen überlesen
Line Input #1, sTxt
Next n
Do Until EOF(1) Or iRow > 2888
Line Input #1, sTxt
sText = sText & ";" 'damit hinter C ein ; steht falls c letzter wert in Zeile
sTxt = Right(sTxt, Len(sTxt) - InStr(sTxt, ";")) ' A weg
sTxt = Right(sTxt, Len(sTxt) - InStr(sTxt, ";")) ' B weg
Cells(iRow, icol).Value = Left(sTxt, InStr(sTxt, ";") - 1) 'C in F schreiben
iRow = iRow + 1
Loop
Close
End Sub
Danke
Heiko
Betrifft: AW: nochmal txt.Import
von: geri
Geschrieben am: 02.10.2003 17:33:18
Hallo Heiko
ergäzte am schluss den Code
Sheets("Tabelle1").Copy Before:=Workbooks("KBR01.xls").Sheets _
(1)
dann wird das Quellblatt ins KBR01 gestellt als Kopie und zear am Anfang --> vor Blatt1
gruss geri
Betrifft: AW: nochmal txt.Import
von: Heiko F.
Geschrieben am: 02.10.2003 17:39:26
Hallo Geri,
bin newbie ,
wo muß ich das Teil genau einfügen?
Danke
Heiko
Betrifft: AW: nochmal txt.Import
von: geri
Geschrieben am: 02.10.2003 17:43:58
Heiko
vor end SUB
gruss geri
Betrifft: AW: nochmal txt.Import
von: Heiko F.
Geschrieben am: 02.10.2003 17:58:28
Hallo Geri,
da kommt Fehler 'Index außerhalb des gültigen Bereiches'
Heiko
Betrifft: AW: nochmal txt.Import
von: geri
Geschrieben am: 02.10.2003 18:37:35
da hat es Adressfehler nehme an das Zielfile ist der Titel falsch
bitte kontrolliere dies
sonst gehe einfach zu EXTRAS / mAKROS UND ZEICHNE EINFACH GENAU DAS AUF WAS DU MÖCHTEST Zb STARTE Aufzeichnung --> Blatt kopieren, Ziel öffnen usw.
und dann füge diesen Code vor End
Sub ein oder schreibe vor END
Sub Call "dein Name von Makro"
hat den Vorteil du kannst die Vorgänge auch für die Zukunft besser nachvollziehen
gruss geri
Betrifft: AW: nochmal txt.Import
von: Heiko F.
Geschrieben am: 02.10.2003 21:42:42
Ok ich versuchs mal.
Vielen Dank für Deine Mühe.
Alles Gute.
Heiko