Insert an image into a userform using the browse option.
Solved
Bob0876
Posted messages
41
Status
Member
-
Bob0876 Posted messages 41 Status Member -
Bob0876 Posted messages 41 Status Member -
Hello, I am creating a form and I would like to allow the display of any image using the browse option.
What I mean is that anyone who uses my form can add an image by searching for it in their folders.
Thank you,
What I mean is that anyone who uses my form can add an image by searching for it in their folders.
Thank you,
3 answers
Hello,
In your UserForm:
- draw an Image control (named Image1)
- draw a CommandButton (named CommandButton1, Caption property: Browse...)
The code for your button is:
--
🎼 Best regards,
Franck 🎶
In your UserForm:
- draw an Image control (named Image1)
- draw a CommandButton (named CommandButton1, Caption property: Browse...)
The code for your button is:
Private Sub CommandButton1_Click() Dim FichImg As Variant FichImg = Application.GetOpenFilename("All file types (*.*),*.*") 'If no file is selected, go to error handling (NoFile) If FichImg = False Then GoTo NoFile 'If the selected file is not an image 'the error handling will process the insertion line 'do nothing and go to error handling (NotAnImage) On Error GoTo NotAnImage 'Attempt to insert the file in the Image1 control Me.Image1.Picture = LoadPicture(FichImg) Exit Sub 'error handling NoFile: MsgBox "You must select an image file to insert.", vbCritical Exit Sub NotAnImage: MsgBox "The chosen file format is not suitable.", vbCritical End Sub --
🎼 Best regards,
Franck 🎶