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
|
Dim Img As String 'de portée module afin de mémoriser le chemin et le nom du fichier image pour l'enregistrement dans le classeur
Private Sub CommandButton1_Click()
Dim Plage As Range
Dim Tbl
Dim I As Integer
'défini la plage en feuille "Feuil1" adapter le nom...
With Worksheets("Feuil1")
'plage de A2 à Mx. Les cellules de la colonne M sont sensées être toutes renseignées
Set Plage = .Range(.Cells(3, 1), .Cells(.Rows.Count, 13).End(xlUp))
End With
'crée un tableau contenant les noms des contrôles où récuperer les valeurs
Tbl = Array("TextBox1", "TextBox2", "TextBox3", "ComboBox1", "TextBox4", "TextBox5", "TextBox6", "TextBox7", "TextBox8", "TextBox9", "TextBox10", "TextBox11")
'décale d'une ligne
With Plage.Rows(Plage.Rows.Count + 1)
'boucle pour inscription des valeurs
For I = 1 To 12
.Cells(1, I + 1).Value = Me.Controls(Tbl(I - 1)).Text
Next I
'insertion de l'image
With .Cells(1, 1)
If Img <> "" Then
Worksheets("Feuil1").Shapes.AddPicture Img, True, True, .Left, .Top, .Width, .Height
End If
End With
Img = ""
End With
End Sub
'utilisé pour la récup de l'image sur le disque ici, "CommandButton2" donc adapter le nom si différent...
Private Sub CommandButton2_Click()
With Application.FileDialog(3)
.Show
On Error Resume Next 'si annuler
Img = .SelectedItems(1)
If Err.Number <> 0 Then Exit Sub
End With
Image1.Picture = LoadPicture(Img)
End Sub
Private Sub UserForm_Initialize()
Dim I As Integer
'un exemple pour populer le combo
For I = 1 To 10
ComboBox1.AddItem "Element " & I
Next I
End Sub |
Partager