Forum Discussion
vjjmm
Feb 07, 2022Copper Contributor
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 picture...
- Feb 07, 2022
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.
HansVogelaar
Feb 07, 2022MVP
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.