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
| Private Sub Bouton_Import_01_Click()
Dim OldPath as String 'Ancien chemin du fichier
Dim NewPath As String 'Nouveau chemin du fichier
Dim oFD As FileDialog 'Boite de dialogue
Dim OldSpec As ImportExportSpecification 'Ancienne spéficication
Dim NewSpec As ImportExportSpecification 'Nouvelle spécification
Dim x As Integer 'Compteur
'----------------------------------------------------------------
'----- Permet de voir la structure de la spec d'origine -----
'----------------------------------------------------------------
Open "\\Path où l'on veut sauvegarder la spec d'origine\SpecsOrigine.txt" For Output As #1
Write #1, CurrentProject.ImportExportSpecifications(nom de la spec d'origine).XML
Close #1
'-------------------------------------------------------------------
'----- Ouvre la boite de dialogue selection de fichier -----
'-------------------------------------------------------------------
'Paramètre la fenêtre Ouvrir
Set oFD = Application.FileDialog(msoFileDialogOpen)
With oFD 'Ajoute les filtres pour fichiers textes et tous
With .Filters
.Clear
.Add "Fichier", "*.csv*", 1
.Add "Tous", "*.*", 2
End With
.InitialFileName = "" 'Interdit la multisélection
.AllowMultiSelect = False 'Affiche la fenêtre et vérifie qu'un fichier a bien été choisi
If .show Then
NewPath = .SelectedItems(1)
NewPath = Replace(NewPath, "&", "&") 'Gestion caractère spécial dans le chemin (gestion du caractère spécial dans le path, pas forcémentent nécessaire)
Else
Exit Sub
End If
End With
'CurrenctProject.ImportExportSpecifications
If MsgBox("Confirmez-vous l'emploi du fichier" & Chr(10) & NewPath, vbYesNo + vbQuestion + vbDefaultButton2, "Demande de confirmation") = vbYes Then
Screen.MousePointer = 11 'Pointeur souris en forme sablier
'---------------------------------------------------------------------
'----- Effacement de l'ancienne spécification temporaire -----
'---------------------------------------------------------------------
'Effacement ancienne spécification temporaire
For x = 0 To CurrentProject.ImportExportSpecifications.Count - 1
If CurrentProject.ImportExportSpecifications.Item(x).Name = "TemporaryImport" Then
CurrentProject.ImportExportSpecifications.Item("TemporaryImport").Delete
x = CurrentProject.ImportExportSpecifications.Count
End If
Next x
'------------------------------------------------------------
'----- Correction chemin nouvelle spécification -----
'------------------------------------------------------------
OldPath = "\\ Pathe du fichier connu dans la spec d'origine"
Set OldSpec = CurrentProject.ImportExportSpecifications.Item("nom de la spec d'origine")
CurrentProject.ImportExportSpecifications.Add "TemporaryImport", OldSpec.XML
Set NewSpec = CurrentProject.ImportExportSpecifications.Item("TemporaryImport")
NewSpec.XML = Replace(NewSpec.XML, OldPath, NewPath)
NewSpec.Execute
Set NewSpec = Nothing
Bouton_Import_01.Enabled = False
Bouton_Import_02.Enabled = True
Screen.MousePointer = 0 'Pointeur souris en forme sablier
Else
Exit Sub
End If
End Sub |
Partager