copy pictures from userform and paste in excel cell, after click on save button

  • How to copy pictures from userform and paste in excel cell, after click on save button the text is mapping to excel cell but not picture, any modification in below Code.


  • Really Great solution .... It's inserting image from userform to Excel.

    by using below code I tried my best to insert image in particular cell but I am fail.

    Ex; value Text A is pasting in cell A but I tried to insert picture in B but when i modified program its showing Error.

    The Code works fine if i want the image only in excel... but i want Image in Cell B

    any solution ?

    I tried in different way but showing Error

    ex: below line

    Code
    1. .Cells(x + 1, "B").Paste = TransferToSheet Me.Image1, ActiveWorkbook.Sheets(1)
  • The code uses the activecell, so select the cell first. This code selects B2


  • I tried above code Its work fine.

    1) But Problem is once you close excel and reopen the image disappearance and gives message "The linked image cannot be displayed. the file may have been moved, renamed, or deleted verify that the link points the correct file and location"

    2) I am not able to paste it in particular cell .
    any solution ?


  • Don't use Pictures.Insert, use Shapes.AddPicture which allows you to specify if the picture is linked or embedded.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • For example:


    Code
    1. sht.Shapes.AddPicture p, msoFalse, msoTrue, ActiveCell.Left, ActiveCell.Top, -1, -1

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • since last one month i am trying to add images in excel with different code but i am facing this error:"The linked image cannot be displayed. the file may have been moved, renamed, or deleted verify that the link points the correct file and location"

    Is there no solution for this problem/error ? If any one know how to paste image from user form to excel. give example code....

  • Thanks Rory .. The code is working fine without error ... Thank you .


    my one more query ?

    can i add the image in this position cell "B"

    Ex;

    Code
    1. Option Explicit
    2. Dim fpath As String
    3. Private Sub Save_Click()
    4. Dim x As Long
    5. Dim Y As Worksheet
    6. Set Y = Sheets("Data1")
    7. x = Y.Range("A" & Rows.Count).End(xlUp).Row
    8. With Y
    9. .Cells(x + 1, "A").Value = TextA.Text
    10. .Cells(x + 1, "B").Image =sht.Shapes.AddPicture p, msoFalse, msoTrue, ActiveCell.Left, ActiveCell.Top, -1, -1

    In cell "B" ?

    Code
    1. .Cells(x + 1, "B").Image = sht.Shapes.AddPicture p, msoFalse, msoTrue, ActiveCell.Left, ActiveCell.Top, -1, -1
  • The code was written to use activecell for position but you can use any Range object instead of Activecell in that line.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • I coded this for on page where VBA will check for empty line and then Text A will go in Cell "A" and Text C will go in cell "C" for next entry it comes in new line and perform same . But i want to code like Text A In cell "A" and Image by using Shapes.AddPicture in Cell "B" ,text C in Cell"C". For next entry same for next row.

    Is it possible to code for above? any solution ?

  • As I said, replace activecell with the range you want - for example:


    Code
    1. sht.Shapes.AddPicture p, msoFalse, msoTrue, Cells(x + 1, "B").Left, Cells(x + 1, "B").Top, -1, -1

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • I have amended the code in your example toe work with AddPicture as Rory suggested.


    I ave not tested the take picture button, but it should work as well.

  • Thank you very much it's working fine....


    only one query how to code for default file path.

    I am changing code as per different folders.

    ex.

    Code
    1. FileCopy fpath, "C:\Users\Yuvi0007\Desktop\data\" & i & ".JPG"

    I want file path as active worksheet path.

    can we code like that ???