Text ein- auslesen mit VBA
10.02.2004 21:54:44
sLy
Ich habe hier in der ExcelFAQ gefunden das man tabelleninhalte in txt dateien speichern kann, soweit funktioniert auch alles wie es sein soll aber wo speichert er das alles hin?? die txt datei die ich dafür erstellen musste braucht er gar nicht oder schreibt er es darein nur man kann es nicht lesen??
hier noch der Code:
Sub KundenINtxt()
Dim rng As Range
Dim iRow As Integer, iCol As Integer, iFile As Integer
Dim sFile As String, sTxt As String
Set rng = Range("A1").CurrentRegion
sFile = Application.Path & "\" & "Kundendaten.txt"
iFile = FreeFile
Open sFile For Output As iFile
For iRow = 1 To rng.Rows.Count
For iCol = 1 To rng.Columns.Count
sTxt = sTxt & Cells(iRow, iCol).Value & ","
Next iCol
sTxt = Left(sTxt, Len(sTxt) - 1)
Print #iFile, sTxt
sTxt = ""
Next iRow
Close iFile
rng.ClearContents
End Sub
Sub KundenOUTtxt()
Dim iRow As Integer, iFile As Integer
Dim sFile As String, sTxtA As String, sTxtB As String, sTxtC As String
sFile = Application.Path & "\" & "Kundendaten.txt"
If Dir(sFile) = "" Then
MsgBox "Die Kundendaten konnten nicht geladen werden!"
Exit Sub
End If
iFile = FreeFile
Open sFile For Input As iFile
Do Until EOF(iFile)
Input #iFile, sTxtA, sTxtB, sTxtC
iRow = iRow + 1
Cells(iRow, 1).Value = sTxtA
Cells(iRow, 2).Value = sTxtB
Cells(iRow, 3).Value = sTxtC
Loop
Close
End Sub