Home



How to populate an image control in an Excel user-form with data from a worksheet using VBA

How to transfer data from an Excel wprksheet to an Excel form including pictures to an image control
  1. Create an Excel file with names. You can also add other details like address, phon numbers, etc.
  2. Now place all the images and the Excel file in the same folder
  3. In the Excel worksheet with the data place a command button whick on click will open a user form to which you wish to transfer the data including images to an image control
    Private Sub CommandButton1_Click()
    MyUserForm.Show
    EndSub

    image-data-excel-user-form

    When you click on the command button 'show form' a user-form appears. The detailed code of each item on the user form is shown below:
    Private Sub CommandButton1_Click()
    Dim NameFound As Range
    Dim fPath As String
    Row = 2
    For Row = Row To 11
    With Cells(Row, 1)
    TextBox1.Text = Cells(Row, 1)
    Set NameFound = .Find(TextBox1.Value)
    If NameFound Is Nothing Then
    Image1.Picture = LoadPicture(fPath & "nopic.gif")
    Else
    With NameFound
    fPath = ThisWorkbook.Path & "\"
    Image1.Picture = LoadPicture(fPath & "\" & TextBox1.Value & ".jpg")
    MsgBox ("Picture of ") & TextBox1.Value
    End With
    End If
    End With
    Next
    End Sub
    Private Sub CommandButton3_Click()
    End
    End Sub
    Note:
    Keep the Excel file and the image file in the same folder.
    Name the images so that the names for the images and the names entered in the Excel worksheet match.


    Watch the video

Reference

Home