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
| Sub AutomatisationMAJLiaisons()
'
' AutomatisationMAJLiaisons Macro
'
Const nb_fichiers = 24
'Dim nb_fichiers As Integer
'nb_fichiers = NbFichierATraiter()
Dim Path1 As String
Dim Tab_noms(1 To nb_fichiers) As String
Dim Derniere_sauvegarde As String
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Mise à jour de tous les liens en cours..." 'dans la barre d'etat
Application.ScreenUpdating = False ' Pour éviter de voir défiler les actions
' Fichiers texte pour le cas A
Tab_noms(1) = "A_eff"
Tab_noms(2) = "A_mas"
Tab_noms(3) = "A_pro_mas"
Tab_noms(4) = "A_moy"
Tab_noms(5) = "A_d_eff"
Tab_noms(6) = "A_d_mas"
Tab_noms(7) = "A_d_pro_mas"
Tab_noms(8) = "A_d_moy"
Tab_noms(9) = "A_d_dur"
Tab_noms(10) = "A_d_agex"
Tab_noms(11) = "A_d_durm"
Tab_noms(12) = "A_m55_eff"
Tab_noms(13) = "A_m55_mas"
Tab_noms(14) = "A_m55_pro_mas"
Tab_noms(15) = "A_m55_moy"
Tab_noms(16) = "A_m55_pro_moy"
' Fichiers texte pour le B
Tab_noms(17) = "B_pro_eff"
Tab_noms(18) = "B_pro_mas"
Tab_noms(19) = "B_pro_moy"
Tab_noms(20) = "B_m55_eff"
Tab_noms(21) = "B_m55_mas"
Tab_noms(22) = "B_m55_pro_mas"
Tab_noms(23) = "B_m55_moy"
Tab_noms(24) = "B_m55_pro_moy"
'Dossier où sont stockés les fichiers
Path1 = ActiveWorkbook.Path
Sheets("MAJ").Select
Range("A2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Selection.Font.ColorIndex = 10
Range("A2").Select
For i = 1 To nb_fichiers
If ExisteFichier(Tab_noms(i)) Then
Workbooks.Open Filename:=Path1 & "\" & Tab_noms(i) & ".txt"
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False
Derniere_sauvegarde = FileDateTime(Path1 & "\" & Tab_noms(i) & ".txt")
ActiveWindow.Close SaveChanges:=False
ActiveCell.FormulaR1C1 = Tab_noms(i)
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = Derniere_sauvegarde
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = 1
ActiveCell.Offset(1, -2).Select
Else
ActiveCell.FormulaR1C1 = Tab_noms(i)
ActiveCell.Font.ColorIndex = 15
ActiveCell.Offset(0, 1).Select
ActiveCell.ClearContents
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = 0
ActiveCell.Font.ColorIndex = 15
ActiveCell.Offset(1, -2).Select
End If
Next
Columns("B:B").Select
Selection.NumberFormat = "mm/dd/yyyy hh:mm"
Application.ScreenUpdating = True
Application.StatusBar = oldStatusBar
End Sub
Function ExisteFichier(nomFichier As String) As Boolean
ExisteFichier = (Dir(ActiveWorkbook.Path & "\" & nomFichier & ".txt") <> "")
End Function
Function NbFichierATraiter() As Integer
'
' Compteur de fichier texte dans le répertoire courant
'
Dim Fichier As Object
Dim Chemin As String, T As String
Dim NbFichierATraiter As Long
Chemin = ActiveWorkbook.Path
'Traitement
With CreateObject("Scripting.FileSystemObject")
For Each Fichier In .GetFolder(Chemin).Files
If Fichier.Name Like "*.txt" Then
NbFichierATraiter = NbFichierATraiter + 1
End If
Next Fichier
End With
End Function |
Partager