How do I change my code to get the file name instead of the directory name? openDialog.InitialFilename gives me the directory name.
openDialog.FileName gives me the error “Method or data member not found”.
Private Sub btnEditPhoto_Click()
If (txtImageName > "") Then
Application.FollowHyperlink txtImageName
Else
Dim openDialog As Office.FileDialog
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Clear
openDialog.Filters.Add "JPEG Files", "*.jpg"
Dim pickedFile As Boolean
pickedFile = openDialog.Show
If pickedFile Then
txtImageName.SetFocus
txtImageName.Text = openDialog.InitialFileName
End If
End If
End Sub
You want:
In place of:
As you have not allowed multiselect.
So:
If AllowMultiSelect is used, you need to iterate through SelectedItems