1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Sub ImportCSV()
Dim dialogBox As FileDialog
Dim selectedFile As String
Set dialogBox = Application.FileDialog(msoFileDialogFilePicker)
With dialogBox
.Filters.Add "CSV", "*.CSV", 1
.AllowMultiSelect = False
If .Show = True Then
selectedFile = .SelectedItems(1)
End If
Debug.Print selectedFile
End With
If selectedFile <> "" Then
Open selectedFile For Input As #1
Dim rowNumber As Long
Dim lineFromFile As String
Dim lineItems As Variant
Dim itteration As Integer
rowNumber = 1
Do Until EOF(1)
Line Input #1, lineFromFile
lineItems = Split(lineFromFile, ";")
For itteration = 0 To 14
Range("ImportRange").Cells(rowNumber, itteration + 1) = lineItems(itteration)
Next
rowNumber = rowNumber + 1
Loop
Close #1
End If
End Sub |
Partager