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
| Sub Demo1()
Dim S$, SPQ$(), D&, L&, U&, R&
S = ThisWorkbook.Path & "\export.csv"
If Dir(S) = "" Then Beep: Exit Sub
With CreateObject("ADODB.Stream")
.Charset = "utf-8"
.Open
.LoadFromFile S
SPQ = Split(.ReadText, vbCrLf)
.Close
End With
D = UBound(SPQ) + (SPQ(UBound(SPQ)) = "")
If D < 0 Then Beep: Exit Sub
Application.ScreenUpdating = False
L = 1
With Feuil1
.UsedRange.Clear
.Cells(L, 1).Value = SPQ(0)
U = UBound(Split(SPQ(0), ","))
For R = 1 To D
S = SPQ(R)
While UBound(Split(S, """,""")) < U And R < D
R = R + 1
S = S & vbLf & SPQ(R)
Wend
L = L + 1
.Cells(L, 1).Value = S
Next
.[A1].Resize(L).TextToColumns DataType:=xlDelimited, Comma:=True, FieldInfo:=Array([{1, 1}], [{2, 1}], _
[{3, 1}], [{4, 1}], [{5, 4}], [{6, 1}], [{7, 1}], [{8, 1}], [{9, 1}], [{10, 1}])
.UsedRange.Rows.AutoFit
.UsedRange.VerticalAlignment = xlCenter
End With
Application.ScreenUpdating = True
End Sub |