Problem saving images in Macro.

Evkant

New Member
Joined
Jun 25, 2018
Messages
1
Hi!
I have a question using macros:

I'm working on this macro, it's a form to save data from maintenance inspection, and as far everything has been working well with the code but now I have this problem that I suspect is pretty easy to solve but I'm new to VBA Programming. So, I have this code, I'm not going to write it completly because it's too long but goes like this:

Sub GuardarInformacion()


Dim contFila As Long
Dim hoja As Worksheet

Set hoja = Worksheets(1)

contFila = hoja.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row




hoja.Cells(contFila, 1).Value = ComboBox11.Value & Me.TextBox4.Value
hoja.Cells(contFila, 2).Value =
hoja.Cells(contFila, 3).Value = Me.TextBox2.Value
hoja.Cells(contFila, 4).Value = ComboBox11.Value
hoja.Cells(contFila, 5).Value = Me.TextBox4.Value
hoja.Cells(contFila, 6).Value = ComboBox12.Value

(...)

End Sub

But now I need to save pictures too, I already wrote that part, and works perfectly fine in the form:

Private Sub CommandButton10_Click()
insertar4
End Sub


Sub insertar4()
Dim 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


Image18.Picture = LoadPicture(foto)


Image18.PictureSizeMode = fmPictureSizeModeStretch


End Sub


So with this line I can upload images to my form, but now I need the image that I already upload in the form to be save on the cell next to the data continously. What I mean is if the last line of the code is:

hoja.Cells(contFila, 6).Value = ComboBox12.Value
End Sub

which is in the column 6, I need the picture to be saved in the column 7 everytime I click to save the data. I don't now if I've made myself understood but I hope you can help me!








****** id="cke_pastebin" style="position: absolute; top: 808px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">I do not know if I've made myself understood</body>
 
Try...

Code:
    With hoja
        .Shapes.AddPicture _
            Filename:=foto, _
            LinkToFile:=msoFalse, _
            SaveWithDocument:=msoTrue, _
            Left:=.Cells(contFila, 7).Left, _
            Top:=.Cells(contFila, 7).Top, _
            Width:=-1, _
            Height:=-1
    End With

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,855
Messages
6,193,375
Members
453,792
Latest member
Vic001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top