Kiều Mạnh
I don't program, I beat code into submission!!!
- Tham gia
 - 9/6/12
 
- Bài viết
 - 5,538
 
- Được thích
 - 4,135
 
- Giới tính
 - Nam
 
mạnh mới thử code này trên Google thấy chạy OkNhư bác batman1 nói tập tin có định dạng UTF-8 (từ web) nên bạn Mạnh chỉ có thể dùng ADODB. Stream để đọc và ghi nó được thôi. ADODB Stream có thể đọc tên file có dấu chấm than (!) luôn nhé.
Ví dụ:
Mã:sFilePath = ThisWorkbook.Path & "\SIM BANKING!.CSV" Dim oStream As Object Set oStream = CreateObject("ADODB.Stream") With oStream .Open .Type = 1 ' adTypeBinary .LoadFromFile sFilePath .Type = 2 ' adTypeText .Charset = "utf-8" strText = .ReadText(-1) ' adReadAll End With ... 'Code đưa strText vào Sheet'
		Mã:
		
	
	Sub GetCSV()
    Dim strText As String, intRow
    Dim file As String, strLine
    file = "E:\Downloads\VBA_ADO_CSV\SIM BANKING!.csv"
    With CreateObject("ADODB.Stream")
         .Open
         .Type = 1                  ' Private Const adTypeBinary = 1
         .LoadFromFile file
         .Type = 2                  ' Private Const adTypeText = 2
         .Charset = "utf-8"
         strText = .ReadText(-1)    ' Private Const adReadAll = -1
     End With
    intRow = 1
    Cells.Clear
    For Each strLine In Split(strText, Chr(10))
        If strLine <> "" Then
            With Sheet1
                .Cells(intRow, 1) = strLine
                .Cells(intRow, 1).TextToColumns Destination:=Cells(intRow, 1), DataType:=xlDelimited, _
                    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
                    Semicolon:=False, Comma:=True, Space:=False, Other:=False
            End With
            intRow = intRow + 1
        End If
    Next strLine
End Sub
	
	
	  








