Hoabattu3387
New Member
- Joined
- Apr 10, 2019
- Messages
- 1
dear all,
i need import data in text files (alldocs) into spreadsheet excel (BCGD) using ado. But this code have a error. Please help me find the reason and fix for me.
Thanks in advance!
i need import data in text files (alldocs) into spreadsheet excel (BCGD) using ado. But this code have a error. Please help me find the reason and fix for me.
Thanks in advance!
Sub Button2_Click()Dim I As Integer
Dim cn As New ADODB.Connection
Dim RCS As New ADODB.Recordset
Dim flog As FileDialog
Set flog = Application.FileDialog(msoFileDialogFilePicker)
With flog
.AllowMultiSelect = True
.Show
.Filters.Clear
.Filters.Add "textfiles", "*.txt"
End With
For I = 1 To flog.SelectedItems.Count
filename = flog.SelectedItems(I)
cn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Left(filename, Len(filename) - Len(Split(filename, "")(5)) - 1) & ";Extended Properties=""text;HDR=no;FMT=fixed;"";")
With ThisWorkbook.Sheets("ALLDOCS")
a = .[a1048576].End(xlUp).Row
End With
With Sheet1
Sql = "select * from " & Split(filename, "")(5)
.Range("A" & a + 1).CopyFromRecordset cn.Execute(Sql)
End With
Set cn = Nothing
Next
MsgBox ("Completely")
End Sub