Hallo,
momentan lade ich eine CSV über File Dialog soweit so gut, besteht die möglichkeit einen Festen Pfad zu hinterlegen ohne FilePicker usw. ?
Ich habe schon einwenig getüftelt der Code läuft durch aber es passiert nichts bin ein bisschen ratlos.
LG Peter
Sub ImportCSV(Dateiname, ZielTabelle As String)
Dim Ws As Worksheet
Set Ws = ActiveWorkbook.Sheets(16)
If Dateiname <> False Then
Application.ScreenUpdating = False
Workbooks.Open filename:=Dateiname, Local:=True
ActiveSheet.UsedRange.Copy Ws.Cells(1)
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End If
End Sub
Sub StartImportCSV()
ImportCSV "C:\Daten\Test.csv", "CSV Import"
Application.CalculateFull
End Sub
Private Sub CommandButtonImport_Click()
Dim fd As Office.FileDialog
Dim WSh As Worksheet
' Set WSh = ActiveWorkbook.Sheets("Schichten") 'ggf. anpassen
Set WSh = ActiveSheet 'Oder das gerade aktive Blatt nehmen
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Title = "Select a CSV File"
.Filters.Add "CSV", "*.csv", 1
.AllowMultiSelect = False
Dim sFile As String
If .Show = True Then
sFile = .SelectedItems(1)
End If
End With
' Import CSV from FileDialog
If sFile <> "" Then
Open sFile For Input As #1
row_number = 1
Do Until EOF(1)
Line Input #1, LineFormFile
LineItems = Split(LineFormFile, ";")
WSh.Cells(row_number, 1).Resize(1, UBound(LineItems) + 1) = LineItems
row_number = row_number + 1
Loop
Close #1
End If
End Sub
|