Sub laydulieu()
Dim cnn As Object, lrs As Object, SQLquery As String, dc As Long
dc = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
Sheet1.Range("A1:ADO100").ClearContents
Set cnn = CreateObject("ADODB.Connection")
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & ThisWorkbook.FullName & ";Extended Properties=""Excel 8.0;HDR=YES"";"
cnn.Open
SQLquery = " select * from Customers "
lrs.Open SQLquery, cnn
Sheet1.Range("A1").CopyFromRecordset lrs
lrs.Close
cnn.Close
End Sub
chào bạn bạn xem file cua bạn có để trong thư mục có dấu không bạn nhé.
dạ không ah
https://drive.google.com/file/d/1zUbY1gUf6hOB3NPoNxh7hFj5ngM2oCQC/view?usp=sharing thầy thầy xem dùm ah
Bạn cho gitiho xin quyền truy cập nhé
em đã mở quyền thầy giúp dùm ah
https://docs.google.com/spreadsheets/d/1zUbY1gUf6hOB3NPoNxh7hFj5ngM2oCQC/edit?usp=share_link&ouid=103008601495819263078&rtpof=true&sd=true
em gửi lại thầy ah
Sub laydulieu()
Dim cnn As Object, lrs As Object, SQLquery As String, dc As Long
dc = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
Sheet1.Range("A1:ADO100").ClearContents
Set cnn = CreateObject("ADODB.Connection")
Set lrs = CreateObject("ADODB.Recordset")
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;IMEX=0"";"
cnn.Open
SQLquery = " select * from Customers "
lrs.Open SQLquery, cnn
Sheet1.Range("A1").CopyFromRecordset lrs
lrs.Close
cnn.Close
End Sub
Bạn thiếu biến lrs nhé.
dạ cảm ơn thầy , thầy cho em hỏi lrs : là gì vậy thầy?
Chào bạn nó là kiểu thuộc ADODB.Recordset thôi bạn
https://support.microsoft.com/vi-vn/office/thu%E1%BB%99c-t%C3%ADnh-recordset-753d8ef0-6ad9-4731-b116-1788e3276600