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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| Public Fichier As String
Sub MAJ_BDD_STVAD()
'Suppression des anciennes données ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Définition des dates
DADEB = InputBox("Entrez la date du premier fichier STV au format aaaammjj", "Date")
If DADEB = "" Then
MsgBox ("Date non renseignée. Merci de renseigner la date")
DADEB = InputBox("Entrez la date du premier fichier STV au format aaaammjj", "Date")
End If
DAFIN = InputBox("Entrez la date du dernier fichier STV au format aaaammjj", "Date")
If DAFIN = "" Then
MsgBox ("Date non renseignée. Merci de renseigner la date")
DAFIN = InputBox("Entrez la date du dernier fichier STV au format aaaammjj", "Date")
End If
'Lancement d'une requête SQL de suppression ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL = "DELETE Date_recep "
SQL = SQL + "FROM STV_AD "
SQL = SQL + "WHERE Date_recep between " & DADEB & " and " & DAFIN & ";"
'MsgBox (SQL)
CurrentDb.Execute (SQL)
'Alimentation de la base de données à partir d'un fichier Excel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Définition pour le lancement d'Excel
Dim Xl As Excel.Application
Dim Classeur As Excel.Workbook
Dim Feuille As Excel.Worksheet
'Ouverture d'Excel
Set Xl = New Excel.Application
Xl.Visible = True
'Ouverture du Classeur Excel
For l = DADEB To DAFIN
If FileExists("N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN A REEX_" & l & ".CSV") = True Then
Set Classeur = Xl.Workbooks.Open("N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN A REEX_" & l & ".CSV")
Else
GoTo r
End If
'Affichage de la Feuille Excel à travailler
Set Feuille = Classeur.Worksheets("SPECIFANALYSE COLIS NON POINTES")
'Modification du fichier Excel
Classeur.Activate
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, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 2), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 2), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1)), TrailingMinusNumbers:= _
True
Columns("A:A").Delete
Columns("F:F").Delete
Columns("G:I").Delete
Columns("J:L").Delete
'Columns("G:G").NumberFormat = "@"
Range("A1").Value = "Agence_Départ"
Range("B1").Value = "Date_PEC"
Range("C1").Value = "Date_recep"
Range("D1").Value = "Recep"
Range("E1").Value = "Mode"
Range("F1").Value = "Compte_Tiers"
Range("G1").Value = "CD"
Range("H1").Value = "Nbre_de_Colis"
Range("I1").Value = "Nbre_Colis_non_lus"
'Enregistrement au format xls
ActiveWorkbook.SaveAs Filename:= _
"N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN A REEX_" & l & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
'Variabilise l'accès et le nom du fichier
Fichier = "N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\" & ActiveWorkbook.Name
'Fermeture du Classeur
Classeur.Close True
'Fermeture d'Excel
Xl.Quit
Call Macro1
r:
Next l
'Alimentation de la base de données à partir d'un fichier Excel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Ouverture d'Excel
Set Xl = New Excel.Application
Xl.Visible = True
'Ouverture du Classeur Excel
For l = DADEB To DAFIN
If FileExists("N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN D_" & l & ".CSV") = True Then
Set Classeur = Xl.Workbooks.Open("N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN D_" & l & ".CSV")
Else
GoTo p
End If
'Affichage de la Feuille Excel à travailler
Set Feuille = Classeur.Worksheets("SPECIFANALYSE COLIS NON POINTES")
'Modification du fichier Excel
Classeur.Activate
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, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 2), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 2 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1)), _
TrailingMinusNumbers:=True
Columns("F:H").Delete
Columns("G:I").Delete
Columns("J:L").Delete
'Columns("G:G").NumberFormat = "@"
Range("A1").Value = "Agence_Départ"
Range("B1").Value = "Date_PEC"
Range("C1").Value = "Date_recep"
Range("D1").Value = "Recep"
Range("E1").Value = "Mode"
Range("F1").Value = "Compte_Tiers"
Range("G1").Value = "CD"
Range("H1").Value = "Nbre_de_Colis"
Range("I1").Value = "Nbre_Colis_non_lus"
'Enregistrement au format xls
ActiveWorkbook.SaveAs Filename:= _
"N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\SPECIFANALYSE COLIS NON POINTES EN D_" & l & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
'Variabilise l'accès et le nom du fichier
Fichier = "N:\Calexpress\13 - METHODES\13.2 Public\13.2.3 Divers\97 - Bases de données\POINTAGE\Fichier STV\" & ActiveWorkbook.Name
'Fermeture du Classeur
Classeur.Close True
'Fermeture d'Excel
Xl.Quit
Call Macro1
p:
Next l
End Sub
'Lancement de la macro Alimentation BDD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function Macro1()
On Error GoTo Macro1_Err
DoCmd.TransferSpreadsheet acImport, 8, "STV_AD", "" & Fichier & "", True, ""
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function
Function FileExists(nomf) As Boolean
FileExists = Dir(nomf) <> ""
End Function |
Partager