Dale Logan
asked on
Capture file name only in FileDialogFilePicker
Experts,
I am trying to figure out how to use FileDialogFilePicker, but just can't do it. I have a button on a form that I want to allow users to select am image file. I then want that file name entered into a field (ProfilePicName) on the same form. Sounds simple, but I am just too rusty at VBA.
Thanks for any help.
Dale
I am trying to figure out how to use FileDialogFilePicker, but just can't do it. I have a button on a form that I want to allow users to select am image file. I then want that file name entered into a field (ProfilePicName) on the same form. Sounds simple, but I am just too rusty at VBA.
Thanks for any help.
Dale
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may simply have this function in the Module.
Remember to add the reference to the Microsoft Office 16.0 Object Library (16.0 belongs to Excel 2016, find the relevant version in the available references).
Remember to add the reference to the Microsoft Office 16.0 Object Library (16.0 belongs to Excel 2016, find the relevant version in the available references).
Function getFileName() As String
Dim FileName As String
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select An Image File"
.Filters.Clear
.Filters.Add "Image Files", "*.jpg;*.gif;*.png"
.AllowMultiSelect = False
If .Show <> 0 Then
FileName = .SelectedItems(1)
FileName = Mid(FileName, InStrRev(FileName, "\") + 1)
getFileName = FileName
Else
getFileName = "No File Selected"
End If
End With
End Function
And then you may use this function in your code like this...'Assuming you have declared a variable to hold the image file name
Dim strImageFile As String
strImageFile = getFileName
ASKER
Thanks for the help. I had already gone with the first solution. Thanks to the others for your suggestions as well. I am sure I will be using pieces of those as well.
Not sure how you are using the FileDialogFilePicker but perhaps this will help.
Open in new window