AW: csv Textdatei in xls kopieren
22.03.2014 10:08:33
Uwe
Hallo Peter,
das hab ich in der Recherche gefunden. Evtl ein Ansatz.
Option Explicit
Const CsvSeparator = ";"
'**************************************
'Daten aus csv-Datei in EXCEL einlesen*
'**************************************
Sub ImportCSV()
Dim Dateiname
Dim nFileNr As Long
Dim RowCount As Long
Dim csvRow As Integer
Dim temp As String
Dim csvCells() As String
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Tabelle1")
Dateiname = Application.GetOpenFilename("Textdateien,*.csv")
If Dateiname False Then
Application.ScreenUpdating = False
nFileNr = FreeFile
Open Dateiname For Input Access Read As #nFileNr
'Line Input #nFileNr, temp
RowCount = 0
While Not EOF(nFileNr)
Line Input #nFileNr, temp
csvCells = Split(temp, CsvSeparator)
ws.Cells(RowCount, 1).Value = csvCells(0)
ws.Cells(RowCount, 2).Value = csvCells(1)
ws.Cells(RowCount, 3).Value = csvCells(2)
RowCount = RowCount + 1
Erase csvCells
Wend
Close #1
'Hochkomma entfernen
Cells.Find(What:="""", After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Cells.Replace What:="""", Replacement:="", lookat:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Application.ScreenUpdating = True
End If
End Sub
Gruß Uwe