1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Sub GetCol()
Dim strPath As String
Dim strTable As String
Dim strFolder As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
i = 2
strPath = "c:\NicolasHanot\tot.txt"
strTable = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
strFolder = Left(strPath, InStrRev(strPath, "\") - 1)
Set db = DAO.OpenDatabase(strFolder, False, False, _
"Text;Database=" & strFolder & ";HDR=NO;Table=" & strTable)
' F1 = Field numéro 1
Set rs = db.OpenRecordset("SELECT F1 FROM [" & strTable & "]", DAO.dbOpenSnapshot, _
DAO.dbReadOnly, DAO.dbReadOnly)
ActiveSheet.Range("A2").CopyFromRecordset rs
Set rs = Nothing
Set db = Nothing
Range("B2").Select
Application.WindowState = xlMinimized
Do While Cells(i, 1).Value > 0
Cells(i, 2).Value = Left(Cells(i, 1), 10)
Cells(i, 2).NumberFormat = "m/d/yyyy"
Cells(i, 3).Value = Mid(Cells(i, 1), 11, 9)
Cells(i, 3).NumberFormat = "h:mm;@"
Cells(i, 4).Value = Mid(Cells(i, 1), 20, 4)
Cells(i, 4).NumberFormat = "0"
i = i + 1
Loop
End Sub |
Partager