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()
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”)
With NameFound
fPath = ThisWorkbook.Path & “\”
Image1.Picture = LoadPicture(fPath & “\” & TextBox1.Value & “.jpg”)
MsgBox (“Picture of “) & TextBox1.Value
End With
End If
End With
End Sub
Private Sub CommandButton3_Click()
‘Remark: you can also write: Unload Me
End Sub

  • 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.

  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


Leave a Reply

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