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
| Dim Nom As Date
Private O As Worksheet 'déclare la variable O (Onglet)
Private LI As Integer 'déclare la variable LI (LIgne)
Private CTRL As Control 'déclare la variable CTRL (ConTRôLe)
Private Sub UserForm_Initialize() 'à l'initialisation de l'UserForm
Set O = Sheets("RECAPITULATIF") 'définit l'ontglet O
If Nouveau = True Then 'condition : si la variable nouveau est [Vrai]
Me.Caption = "SAISIE DES INTERVENTIONS" 'définit le titre de la boîter de dialogue
LI = O.Cells(Application.Rows.Count, 1).End(xlUp).Row + 1 'définit la ligne LI
TextBox15.Value = WorksheetFunction.Max(O.Columns(2)) + 1 'incrémente le numnéro de l'intervention
Else 'sinon
Me.Caption = "MODIFIER" 'définit le titre de la boîter de dialogue
LI = ActiveCell.Row 'définit la ligne LI
TextBox15.Value = O.Cells(LI, 2).Value 'récupèr ele numéro d'intervention
TextBox5.Value = O.Cells(LI, 4).Value
TextBox1.Value = O.Cells(LI, 5).Value
TextBox7.Value = O.Cells(LI, 7).Value
TextBox2.Value = O.Cells(LI, 8).Value
TextBox11.Value = O.Cells(LI, 13).Value
TextBox17.Value = O.Cells(LI, 19).Value
TextBox4 = Format(O.Cells(LI, 10), "dd/mm/yyyy")
TextBox3.Value = O.Cells(LI, 9).Value
TextBox13.Value = O.Cells(LI, 16).Value
TextBox12.Value = O.Cells(LI, 15).Value
TextBox14.Value = O.Cells(LI, 17).Value
TextBox16.Value = O.Cells(LI, 18).Value
ComboBox2.Value = O.Cells(LI, 3).Value
ComboBox6.Value = O.Cells(LI, 6).Value
ComboBox3.Value = O.Cells(LI, 14).Value
ComboBox5.Value = O.Cells(LI, 12).Value
ComboBox4.Value = O.Cells(LI, 11).Value
ComboBox3.Value = O.Cells(LI, 14).Value
Nom = Format(O.Cells(LI, 10), "yyyy")
End If
Nouveau = False
ComboBox2.List() = Array("", "CAEN", "ANGERS", "LE MANS", "TOURS", "POITIERS", "NANTES", "RENNES", "BREST", "BORDEAUX")
ComboBox3.List() = Array("", "DIAGNOSTIC", "MISE EN SERVICE", "VISITE", "SERVICE 0")
ComboBox4.List() = Array("", "TERMINE", "EN COURS")
ComboBox5.List() = Array("", "ANNULE", "FABRICANT", "OK")
ComboBox6.List() = Array("", "SALMSON", "GRUNDFOS", "PNEUMATEX", "WILO", "XYLEM", "AUTRE")
End Sub
Private Sub CommandButton1_Click() 'bouton "VALIDATION"
For Each CTRL In Me.Controls 'boucle sur tous les contrôles de l'userForm
'si la propriété [Tag] du contrôle n'est pas vide, renvoie la valeur du contrôle CTRL
'dans la cellule ligne LI colonne [Tag] (converti en entier) du contrôle, de l'onglet O
If CTRL.Tag <> "" Then O.Cells(LI, CInt(CTRL.Tag)).Value = CTRL.Value
Next CTRL 'prochain contrôle de la boucle
Sheets("RECAPITULATIF").Select
Range("A1").Select
Dim Ladate As String
Dim FSO As Object, sNomDossier As String
Noma = Format(Nom, "yyyy")
Range("F488").Value = Noma
LeParcours = TextBox15.Value
Ladate = Format(TextBox4, "yyyy")
If TextBox4.Value = "" Then
Ladate = Year(Date)
End If
sNomDossier = "HYD" & LeParcours
Set FSO = CreateObject("Scripting.FileSystemObject")
sChemin = "C:\Users\nathan\Dropbox\HYD" & Noma & "\" & sNomDossier & "/"
sChemin1 = "C:\Users\nathan\Dropbox\HYD" & Ladate & "\" & sNomDossier & "/"
If TextBox4.Value = Noma Then Unload Me
FSO.CreateFolder (sChemin1)
If FSO.FolderExists(sChemin) Then FSO.CopyFolder (sChemin), (sChemin1)
If FSO.FolderExists(sChemin) Then FSO.DeleteFolder (sChemin)
Set FSO = Nothing
Range("B65536").End(xlUp).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"C:\Users\nathan\Dropbox\HYD" & Ladate & "\" & sNomDossier & "/"
TextToDisplay = "sNomDossier"
Range("B65536").End(xlUp).Font.Name = "Verdana"
Unload Me 'vide et ferme l'UserForm
If Not IsDate(TextBox4) Then
MsgBox "Date non-présente ou incorrecte"
TextBox4 = ""
End If
End Sub |
Partager