Image (Image1) userform to excel sheet

0

Good morning.

Greetings to all, I'm doing a small macro in excel with vb-userform where I have several text fields, this data is passed to an excel sheet with a button.

This image I want to add it to my sheet. I am using this code, the text fields if you copy it but the image does not.

 Private Sub cmdAgregar_Click()

Sheets("Formulario").Select

NR = Application.WorksheetFunction.CountA(Range("A:A"))

Cells(NR + 1, 1) = txtModelo
Cells(NR + 1, 2) = txtTallaBase
Cells(NR + 1, 3) = txtCliente
Cells(NR + 1, 4) = txtFechaElaboracion
Cells(NR + 1, 5) = txtDescripcion
Cells(NR + 1, 6) = txtTemporada
Cells(NR + 1, 7) = txtEntrega
Cells(NR + 1, 121) = LoadPicture(Image1)

End Sub

The 121 is where I want to show the image and with LoadPicture (Image1), I get error 13, the types do not match.

By means of my button (Upload) it allows me to add the image in the Image tool.

Private Sub cmdCargar_Click()
Public foto As Variant
foto = Application.GetOpenFilename(FileFilter:= _
"Imagen (*.gif;*.jpg;*.jpeg;*.bmp), *.gif;*.jpg;*.jpeg;*.bmp", _
Title:="Seleccionar imagen", MultiSelect:=False)

If foto = False Then
Exit Sub
End If

If Not IsEmpty(Image1.Picture) Then
Image1.Picture = Nothing
End If

Image1.Picture = LoadPicture(foto)
Image1.PictureSizeMode = fmPictureSizeModeStretch
Image1.Width = 100
Image1.Height = 100
End Sub

Now in this loaded image I want to copy or send it to an excel cell Cells(NR + 1, 121) , which method could use some suggestion.

I appreciate your support.

    
asked by Ever 15.08.2018 в 18:26
source

1 answer

0

What I can think of that you do and that I also verified and it works (in Excel 2016) is that you remove your variable foto out of the event of your cmdCargar button so that you can use it in other instances, since The only thing it does is store the route of the image that you are loading.

and inside your button cmdAgregar you send it insert with the following code:

Cells(NR + 1, 121).Select
ActiveSheet.Pictures.Insert (foto)

where foto is the path of the image that you have loaded in your pictureBox before, I hope it serves you.

    
answered by 17.08.2018 в 22:38