Forum Discussion
VBA: how do I enter an image into a userform?
Hi guys, I am doing a userform in which I need the users to select an image from their desktop and upload it in the userform. does anyone have an Idea of how to do that? the userform info+the pictures need to be then saved in a database which I made in a second sheet.
Create an Image control on the userform and set its PictureSizeMode property to 3 - fmPictureSizeModeZoom.
Create a command button on the userform, name it cmdPicture and create the following On Click event procedure for it:
Private Sub cmdPicture_Click() Dim strPic As String With Application.FileDialog(1) ' msoFileDialogOpen .Filters.Clear .Filters.Add "Image Files (*.jpg, *.png, *.bmp, *.gif)", "*.jpg,*.png,*.bmp,*.gif" If .Show Then strPic = .SelectedItems(1) Me.Image1.Picture = LoadPicture(strPic) Else Beep End If End With End Sub
Here, Image1 is the name of the Image control.
See the attached sample workbook.
2 Replies
- kadirgulerBrass Contributor
You can find a template that created to display images in the userform at this link. Additionally, when you click on the image, it can be viewed in its original size. https://merkez-ihayat.blogspot.com/2025/04/address-list-with-picture-in-excel.html
Create an Image control on the userform and set its PictureSizeMode property to 3 - fmPictureSizeModeZoom.
Create a command button on the userform, name it cmdPicture and create the following On Click event procedure for it:
Private Sub cmdPicture_Click() Dim strPic As String With Application.FileDialog(1) ' msoFileDialogOpen .Filters.Clear .Filters.Add "Image Files (*.jpg, *.png, *.bmp, *.gif)", "*.jpg,*.png,*.bmp,*.gif" If .Show Then strPic = .SelectedItems(1) Me.Image1.Picture = LoadPicture(strPic) Else Beep End If End With End Sub
Here, Image1 is the name of the Image control.
See the attached sample workbook.