Hello all,
mình mới lập trình VBA exel. Đang gặp vấn đề là dữ liệu mình lấy bị lỗi unicode không đọc được
Dữ liệu mình lấy ok nhưng khi viết vào file exel thì bị lỗi unicode không đọc được
mọi người có cách nào chỉ giúp
Thanks
mình mới lập trình VBA exel. Đang gặp vấn đề là dữ liệu mình lấy bị lỗi unicode không đọc được
Mã:
Sub VBA_SQL_BaoCao()
Dim sSQLQry As String
Dim ReturnArray
Dim Conn As New ADODB.Connection
Dim hp_rs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
Dim file_report_car As String
Dim ws As Worksheet
Dim ws_hp As Worksheet
Dim wb As Workbook
Dim ws_b As Worksheet
Dim lastRow As Integer
Dim i As Integer
'DBPath = ThisWorkbook.FullName 'Refering the sameworkbook as Data Source
DBPath = ThisWorkbook.Path & "\tonghop_hp.xlsx"
file_report_car = ThisWorkbook.Path & "\output\BaoCaoDoanhThu.xlsx"
'delete workbook'
'create workbook'
'If Len(Dir$(file_report_car)) > 0 Then'
'Kill file_report_car'
'End If'
'You can provide the full path of your external file as shown below
'DBPath ="C:\InputData.xlsx"
sconnect = "Provider=MSDASQL;DSN=Excel Files;DBQ=" & DBPath & ";HDR=No';CharSet=utf-8;Auto Translate=False;"
'If any issue with MSDASQL Provider, Try the Microsoft.Jet.OLEDB:
'sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & ";Extended Properties="Excel 8.0;HDR=No;"
'sconnect = "ODBC;Driver={Microsoft Excel Driver (*.xls)};DSN=Excel Files;DBQ=D:\TDN_DATA\tonghop_hp.xlsx;MaxBufferSize=2048;PageTimeout=5;ReadOnly=False;content=text/x-ms-odc; charset=utf-8;"
Conn.Open sconnect
hp_sSQLSting = "SELECT Ten, KHACH_HANG, MA_TUYEN, Count(*) AS So_Luong " & "FROM [HP$]" & " WHERE MA_TUYEN IS NOT NULL GROUP BY MA_TUYEN" & " ORDER BY TUYEN"
hp_rs.Open hp_sSQLSting, Conn
Set wb = Workbooks.Open(file_report_car)
'wb.Sheets(1).Name = "HP"
'wb.SaveAs file_report_car
Set ws = wb.Sheets(1)
'clear data range
lastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("A3:F" & lastRow).ClearContents
ws.Range("A2").CopyFromRecordset hp_rs
mọi người có cách nào chỉ giúp
Thanks