Anzeige
Archiv - Navigation
860to864
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
860to864
860to864
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

csv-Import - mal klappts, mal nicht...

csv-Import - mal klappts, mal nicht...
17.04.2007 17:42:00
Timo
Hallo!
Der folgende Code ist in der Datei "Ergebnis-v1.xls" über einen eigenen Menüeintrag aufrufbar. Es soll aus einer csv-Datei (Semikolon-getrennt) ein bestimmter Datenbereich ( 30 -40) in die Ergebnis-Tabelle kopiert werden .
Der Code an sich klappt auch auf meinem PC, auf einem zweiten (Hard- und Software identisch) wird die csv-Datei beim Öffnen jedoch nicht in Spalten zerlegt, sodass die Auswahl des Datenbereichs missglückt.
Woran kann das liegen? Kann man das richtige Importieren per VBA einschalten?
Kann ich das "Spalten kopieren und einfügen " optimieren?
Danke im Voraus
Timo

Private Sub Ordersatz_Import()
Dim vDatei As Variant
Dim name2 As String
Dim x As Integer, Startx As Integer, Endx As Integer
ChDrive "K"
ChDir "K:\TRANSFER"
vDatei = Application.GetOpenFilename(FileFilter:="CSV-Dateien (*.csv), *.csv", _
Title:="Bitte aktuellen Ordersatz auswählen")
If vDatei = False Then Exit Sub
On Error Resume Next
Workbooks.Open Filename:=vDatei
On Error GoTo 0
name2 = ActiveWorkbook.Name
For x = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
If Cells(x, 1).Value = "30" Then
Startx = x
Exit For
End If
Next
For x = Startx To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
If Cells(x, 1).Value = "41" Then
Endx = x - 1
Exit For
End If
Next
range("B" & Startx & ":D" & Endx).Copy
Windows("Ergebnis_v1.xls").Activate
Sheets("Artikeltabelle").Select                        ' optimierbar?
range("A3").Select
ActiveSheet.Paste
range("A1").Select
Application.DisplayAlerts = False
Windows(name2).Close (False)
Application.DisplayAlerts = True
End Sub


2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: csv-Import - mal klappts, mal nicht...
18.04.2007 09:31:38
Rudi
Hallo,
der CSV-Import und Export per VBA klappt nicht reibungslos. Das sollte dein Problem beheben:

Private Sub Ordersatz_Import()
Dim vDatei As Variant
Dim x As Integer, Startx As Integer, Endx As Integer
Dim wksTmp As Worksheet, intFile As Integer
Dim strTmp As String, vntTmp As Variant
Dim lngLastRow As Long
ChDrive "K"
ChDir "K:\TRANSFER"
vDatei = Application.GetOpenFilename(FileFilter:="CSV-Dateien (*.csv), *.csv", _
Title:="Bitte aktuellen Ordersatz auswählen")
If vDatei = False Then Exit Sub
Set wksTmp = Workbooks.Add.Sheets(1)
lngLastRow = 1
intFile = FreeFile
Open vDatei For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strTmp
vntTmp = Split(strTmp, ";")
vntTmp = WorksheetFunction.Transpose(WorksheetFunction.Transpose(vntTmp))
With wksTmp
.Range(.Cells(lngLastRow, 1), .Cells(lngLastRow, UBound(vntTmp))) = vntTmp
End With
lngLastRow = lngLastRow + 1
strTmp = ""
Loop
Close intFile
With wksTmp
For x = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(x, 1).Value = "30" Then
Startx = x
Exit For
End If
Next
For x = Startx To .Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(x, 1).Value = "41" Then
Endx = x - 1
Exit For
End If
Next
.Range(.Cells(Startx, 2), .Cells(Endx, 4)).Copy _
ThisWorkbook.Sheets("Artikeltabelle").Range("A3")
End With
wksTmp.Parent.Close False
End Sub


Gruß
Rudi
Eine Kuh macht Muh, viele Kühe machen Mühe

Anzeige
AW: csv-Import - mal klappts, mal nicht...
18.04.2007 19:18:17
Timo
Danke!
Ich werde mich da mal durcharbeiten, um das auch richtig zu verstehen...
mfg
Timo

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige