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