Filesystemobject File Picker Does not Highlight Initial File

sjlevine34

New member
Local time
Today, 09:45
Joined
May 14, 2014
Messages
5
I am using the following code to select files using Microsoft Office's file dialog:

Public Function fTestFilePicker() As String
Dim fdFileSelection As Office.FileDialog, lstrFileName As String
Const kInitialFile = "F:\Testbed\Test.txt"

Set fdFileSelection = Application.FileDialog(msoFileDialogFilePicker)

With fdFileSelection
.AllowMultiSelect = False
.Title = "Select File to be Hyperlinked:"
.Filters.Clear
.InitialFileName = kInitialFile
.InitialView = msoFileDialogViewDetails

If .Show = True Then
lstrFileName = .SelectedItems(1)
Else
lstrFileName = "Operation cancelled"

End If
End With

fTestFilePicker = lstrFileName

End Function

When I execute it, the file picker goes to the right folder but does not highlight the file test.txt even though that file name shows in the File name text box. Is there any way to correct this?
 
I tried .SelectedItems.item(1) and it does not solve the problem. Understand that the problem was never with returning the name of the selected file. It is just with the initial file being highlighted when the field is entered.
 
You know, until I actually looked I didn't realize you are correct. The name does show in the File Name box at the bottom but the actual file is not highlighted. (So, I guess it never concerned any of my Users.)

And after re-reading the MSDN article, I'm not sure you can highlight the actual file as the purpose if the File Dialog is for the User *select* the file...
http://msdn.microsoft.com/en-us/library/office/ff196794(v=office.15).aspx

Hopefully, someone will pass by will an option but I'm stumped!
 
My major concern is a user inadvertently blundering into the dialog and breaking the link
 
Not sure I understand, no matter what they do the way you have it set up it will open to the Directory where the File is. You've hard coded it.
 
Actually, what I posted was a test program that isolates the issue. In the real application, the links are stored in the database. What concerns me is that, when the filepicker window displays, the file is highlighted in the filename field and one inadvertent keystroke can wipe it out. I working with this application, I have blundered into the filepicker window.
 
Hmm, so, you are trying to prevent Users from removing the File that is displayed. Nope, I know of no way to prevent that though I see your problem. For that matter, one keystroke and they could wipe out the highlighted File ot Folder... wish I had an answer for that...:(
 

Users who are viewing this thread

Back
Top Bottom