Magic Polygon
New Member
- Joined
- Aug 20, 2023
- Messages
- 30
- Office Version
- 2019
- Platform
- Windows
I have allowed only *.bmp, *.cur, *.gif, *.ico, *.jpg, and *.wmf file formats through filtering, but Internet Shortcuts are visible and selectable in the File Dialog. I don't know how to hide out the Internet shortcuts or reprompt the user for a valid choice of file.
VBA Code:
Private Sub UploadImageCommandButton_Click()
'Declare a variable as a FileDialog object
Dim UploadPictureFileDialog As FileDialog
'Path to the image
Dim ImagePath As String
'Create a FileDialog object as a File Picker dialog box
Set UploadPictureFileDialog = Application.FileDialog(msoFileDialogFilePicker)
'Reference the File Dialog object
With UploadPictureFileDialog
'Remove all filters currently applied to the file dialog box
.Filters.Clear
'Sets the title of the file dialog box displayed
.Title = "Select a Photo"
'Adds a filter to the file dialog box at position 1 of the list of filters
.Filters.Add "Images", "*.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf", 1
'Only a single file can be selected from the dialog box
.AllowMultiSelect = False
End With
'Use the Show method to display the File Picker dialog box and return the user's action
'The user pressed the button
If UploadPictureFileDialog.Show = -1 Then
'Store the path of the selected item
ImagePath = UploadPictureFileDialog.SelectedItems(1)
'Fit the image into the picture frame
UploadedImage.Picture = LoadPicture(ImagePath)
UploadedImage.PictureSizeMode = fmPictureSizeModeZoom
'The user pressed Cancel
Else
End If
End Sub