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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| Sub importFANTOIR()
Set Monclasseur = ThisWorkbook
Monclasseur.Activate
' Import du fichier FANTOIR
ChDir "H:\temp" ' Emplacement du fichier source
ChDrive "H:"
monfichier = Application.GetOpenFilename
If monfichier <> False Then
rep = MsgBox("Ouvrir : " & monfichier, vbOKCancel)
End If
If rep = 1 Then
' recompose le nom à l'envers pour détecter le premier \
toto = Len(Trim(monfichier))
montest = ""
titi = Trim(monfichier)
Do
titi = Right(titi, 1)
If titi = "\" Then
' recompose le mot à l'endroit
toto = Len(montest)
titi = montest
Do
titi = Right(titi, 1)
p = p + 1
Monfic = Monfic + titi
titi = Mid(montest, 1, toto - p)
If p = i Then Exit Do
Loop
Exit Do
Else
i = i + 1
montest = montest + titi
titi = Mid(Trim(monfichier), 1, toto - i)
End If
Loop
If UCase(Left(Monfic, 4)) = "FANR" Then
Application.Cursor = xlWait
Application.DisplayStatusBar = True
Application.StatusBar = "Import du fichier Identifiant du Local en cours ..."
Application.ScreenUpdating = False
Dim maligne As String
' longueur de l'enregistrement total
Dim mazone(150) As String
' Ouvre le fichier en lecture.
Open monfichier For Input As #1
Direction = False
' Liste des rues
Sheets("Fantoir").Select
Range("A2:AZ60000").Clear
Set MaParcelle = Range("A2")
Do While Not EOF(1)
' Ne lit que les chaînes de caractères ne retourne pas
' les codes CHr(13)
Input #1, maligne '
' En tête commun à tous les articles
mazone(1) = Mid(Trim(maligne), 1, 2) 'ccodep
mazone(2) = Mid(Trim(maligne), 3, 1) 'ccodir
mazone(3) = Mid(Trim(maligne), 4, 3) 'ccocom
'If mazone(3) = "066" Then 'Selectionne la communne (66 = CHATELLERAULT)
If Len(Trim(Mid(Trim(maligne), 74, 1))) = 0 Then 'supprime les entités annulées "O" et "Q" en (74,1)
mazone(4) = "'" + Mid(Trim(maligne), 7, 4) 'ccoriv (Impose une zone texte)
mazone(5) = Mid(Trim(maligne), 11, 1) 'cleriv
mazone(6) = Mid(Trim(maligne), 12, 4) 'natvoi
mazone(7) = Mid(Trim(maligne), 16, 26) 'libvoi
mazone(8) = Mid(Trim(maligne), 42, 1) 'filler
mazone(9) = Mid(Trim(maligne), 43, 1) 'typcom
mazone(10) = Mid(Trim(maligne), 44, 2) 'filler
mazone(11) = Mid(Trim(maligne), 46, 1) 'ruractu
mazone(12) = Mid(Trim(maligne), 47, 2) 'filler
mazone(13) = Mid(Trim(maligne), 49, 1) 'carvoi
mazone(14) = Mid(Trim(maligne), 50, 1) 'indpop
mazone(15) = Mid(Trim(maligne), 51, 2) 'filler
mazone(16) = Mid(Trim(maligne), 53, 7) 'popreel
mazone(17) = Mid(Trim(maligne), 60, 7) 'poppart
mazone(18) = Mid(Trim(maligne), 67, 7) 'popfict
mazone(19) = Mid(Trim(maligne), 74, 1) 'annul
mazone(20) = Mid(Trim(maligne), 75, 4) 'janannul
mazone(21) = Mid(Trim(maligne), 82, 4) 'jancrea
mazone(22) = Mid(Trim(maligne), 89, 15) 'filler
mazone(23) = Mid(Trim(maligne), 104, 5) 'ccovoi
mazone(24) = Mid(Trim(maligne), 109, 1) 'indclvoi
mazone(25) = Mid(Trim(maligne), 110, 1) 'indldnb
mazone(26) = Mid(Trim(maligne), 111, 2) 'filler
mazone(27) = Mid(Trim(maligne), 113, 8) 'motclass (permet de restituer l'ordre alphabétique)
mazone(28) = Mid(Trim(maligne), 121, 30) 'filler
Monclasseur.Sheets("Fantoir").Select
MaParcelle.Select
For i = 1 To 28
Selection.Offset(0, i - 1).Formula = mazone(i)
Next
Set MaParcelle = MaParcelle.Offset(1, 0)
End If
'End If
Loop
Close #1 ' Ferme le fichier.' fin d'import
MsgBox "L'import est terminé !"
Call Majecran
Else
rep = MsgBox("Le fichier d'import doit être FANR.* !", vbCritical)
rep = MsgBox("L'import est annulé !", vbCritical)
End If
Else
rep = MsgBox("L'import est annulé !", vbCritical)
End If
Call Majecran
End Sub
Sub Majecran()
Application.ScreenUpdating = True
Application.StatusBar = False
Application.DisplayStatusBar = True
'redonne la main à Excel sur la barre des tâches
Application.Cursor = xlDefault
End Sub |
Partager