Đây là đoạn code e copy từ internet nhưng nó báo lỗi Provider. Hiện tại em đang xài excel 365. Khi record macro thì nó ra provider là: Provider=Microsoft.Mashup.OLEDB.1
Nhờ mọi người xem thử giúp em với ạ.
![217614 217614](https://www.giaiphapexcel.com/diendan/data/attachments/174/174602-3fb325d435f603d8a129cc63997f5ebf.jpg?hash=P7Ml1DX2A9)
![217616 217616](https://www.giaiphapexcel.com/diendan/data/attachments/174/174604-1f8c11179ddcc9032675346ad46b33a5.jpg?hash=H4wRF53cyQ)
Nhờ mọi người xem thử giúp em với ạ.
Mã:
Sub ImportLargeFile()
'Imports text file into Excel workbook using ADO.
'If the number of records exceeds 65536 then it splits it over more than one sheet.
Dim strFilePath As String, strFilename As String, strFullPath As String
Dim lngCounter As Long
Dim oConn As Object, oRS As Object, oFSObj As Object
'Get a text file name
strFullPath = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Please select text file...")
If strFullPath = "False" Then Exit Sub 'User pressed Cancel on the open file dialog
'This gives us a full path name e.g. C:\temp\folder\file.txt
'We need to split this into path and file name
Set oFSObj = CreateObject("SCRIPTING.FILESYSTEMOBJECT")
strFilePath = oFSObj.GetFile(strFullPath).ParentFolder.Path
strFilename = oFSObj.GetFile(strFullPath).Name
'Open an ADO connection to the folder specified
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"""
Set oRS = CreateObject("ADODB.RECORDSET")
'Now actually open the text file and import into Excel
oRS.Open "SELECT * FROM " & strFilename, oConn, 3, 1, 1
While Not oRS.EOF
Sheet1.Range("A1").CopyFromRecordset oRS, 65536
Wend
oRS.Close
oConn.Close
End Sub
![217614 217614](https://www.giaiphapexcel.com/diendan/data/attachments/174/174602-3fb325d435f603d8a129cc63997f5ebf.jpg?hash=P7Ml1DX2A9)
Bài đã được tự động gộp:
Bài đã được tự động gộp:
![217616 217616](https://www.giaiphapexcel.com/diendan/data/attachments/174/174604-1f8c11179ddcc9032675346ad46b33a5.jpg?hash=H4wRF53cyQ)
Lần chỉnh sửa cuối: