PDA

View Full Version : Insert Photo in Cell, using Userform



haridevadiga
03-09-2009, 11:13 PM
Dear User,

I have a query while doing this thing. I have a userform which have three things.

(1) Image1
(2) Attach Photos Button (cmdattach)
(3) Submit Photos Button (cmdsubpic)

When i click on Attach Photos Button its get a Dialog Box of Choose Image File, if i choose image it get displayed in Image1.

Now the problem which i am facing is :

When i click on Submit Photos Button the image is not going to particular place.. I mean to say image is not appearing on Worksheet. Its showing some alphanumeric things.

Please test the file before writing u r code. To know what i want exactly

Warm Regards,
Harindra Devadiga

GTO
03-10-2009, 03:17 AM
Fairly cheesy, but maybe enough to get you started. I would note that if you are going to use the image control to preview the pic, then you are limited to the formats taht the control supports. For instance, (in 2000 leastwise) you wouldn't be able to insert a .png pic.

Anyways, try:

Dim fname As String

Private Sub cmdattach_Click()


fname = Application.GetOpenFilename(filefilter:= _
"Picture Files(*.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf)," & _
"*.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf", Title:="Select Image To Open")

If fname <> "False" Then
Image1.Picture = LoadPicture(fname)
Me.Repaint
End If

End Sub


Private Sub cmdsubpic_Click()
Dim iRow As String
Dim ws As Worksheet

Set ws = Worksheets("Sheet1")

iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Select

If Not fname = "False" _
And Not fname = vbNullString Then

ActiveSheet.Pictures.Insert (fname)
ws.Cells(iRow, 1).Select
End If
End Sub

Hope this helps,

Mark

haridevadiga
03-10-2009, 04:20 AM
Thanks GTO, but the thing which i want is to every fresh entry i want a next row

Like if i have 3 Images & i want to insert it

Row 1 Image 1
Row 2 Image 2
Row 3 Image 3

Hope you get me... :)

Warm Regards,
Harindra G. Devadiga

georgiboy
03-10-2009, 04:50 AM
Something like this you mean...