Populate Image Control on User Form with Pictures from Worksheet Data Using VBA

How to transfer pictures from Excel worksheet data to a user form image control using VBA

  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
End Sub

How to transfer pictures to image control on user form

Screen shot: Using data on Excel worksheets to transfer pictures to an image control on 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
‘Remark: you can also write: Unload Me
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 below:


Further reading: Load Worksheet Picture Into UserForm Image Control

4 thoughts on “Populate Image Control on User Form with Pictures from Worksheet Data Using VBA

  1. tonygabani

    Sir, through the user form I had created, I can add or Edit data into excel worksheet, I also have an image control on my user form on which I can upload any Image from my computer at run time. My problem is I find it difficult to add / Edit the image to excel work sheet. is this task possible, sir, your assistant will be of great help.

    Reply
    1. Frankie

      Thanks for your post. One other thing is when you are selling your property on your own, one of the challenges you need to be alert to upfront is how to deal with house inspection records. As a FSBO owner, the key concerning successfully transferring your property plus saving money upon real estate agent profits is untdnsearding. The more you realize, the easier your property sales effort will likely be. One area in which this is particularly essential is inspection reports.

      Reply
  2. Chopa James

    How to autoprint data in an excel vba worksheet upon loading it from a userform. Please give help me with the code

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *