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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
Option Compare Database
Option Explicit
Dim fso As New FileSystemObject
Dim f As Folder
Dim fichier As File
Const Chemin = "............"
Dim oApp As Excel.Application
Dim oWkb As Excel.Workbook
Dim oWSht As Excel.Worksheet
Sub importation()
Set oApp = CreateObject("excel.application")
Set oWkb = oApp.Workbooks.Open("...........\0 Liste des tables.xlsx")
Set oWSht = oWkb.Worksheets("Liste des tables non vides")
Set f = fso.GetFolder(Chemin)
Dim a As Integer
a = 1
While oWSht.Range("C" & a) <> ""
a = a + 1
Wend
For Each fichier In f.Files
If Right(fso.GetFile(fichier).Name, 3) = "tab" Then
Debug.Print fichier.Name
Dim nomtable As String
nomtable = fso.GetFile(fichier).Name
nomtable = Mid(nomtable, 1, Len(nomtable) - 4)
Dim i As Integer
i = 1
For i = 1 To a
Dim nomcase As String
nomcase = oWSht.Range("A" & i).Value
If nomcase = nomtable Then Exit For
Next
Dim tablevide As Boolean
If i = a + 1 Then tablevide = True Else tablevide = False
Dim fichierparam
If Not tablevide Then
Set fichierparam = f.CreateTextFile(nomtable & ".ini")
fichierparam.WriteLine "[" & nomcase & " ]"
fichierparam.WriteLine "ColNameHeader = True"
fichierparam.WriteLine "Format = FixedLength"
fichierparam.WriteLine "MaxScanRows = 0"
Dim j As Integer
j = 4
While oWSht.Cells(i, j) <> ""
Dim nomcolonne As String
nomcolonne = oWSht.Cells(i, j)
Dim typecolonne As String
typecolonne = oWSht.Cells(i + 1, j)
typecolonne = Left(typecolonne, 4)
Select Case typecolonne
Case "NUMB"
typecolonne = "Float"
Case "VARC"
typecolonne = "Char"
Case "DATE"
typecolonne = "Date"
Case Else
typecolonne = "Char"
End Select
fichierparam.WriteLine "Col" & j & "=""" & nomcolonne & """ " & typecolonne
j = j + 1
Wend
fichierparam.Close
DoCmd.TransferText acImportDelim, Chemin & "\" & nomtable & ".ini", nomtable, Chemin & "\" & nomtable & ".tab", True
'Kill (Chemin & "\" & nomtable & ".ini")
End If
Else
End If
Next
End Sub |
Partager