Has someone a simple(!) workaround for the default file name appearing to be truncated (on the left) when it is displayed in a File Open Dialog?
The full file name is: "test_default_file.txt"
This is also the actual content of the control, it just appears truncated. Only the rightmost 18 characters are displayed initially. If you put the focus into that text box and move the caret to the left the full file name appears.
So, the problem is "only" that users are confused because they think, the dialog does not pre-select the intended file name. This is aggravated by the fact that in practice the leftmost 8 characters of the file name are important to identify the correct file.
It doesn't make a difference whether I use the built-in Office file dialog or the GetOpenFileNameA API function.
This is a common problem and you find numerous mentions of it on the internet. However, I wasn't able to find a simple solution to it.
My code is bog standard and IMO mostly irrelevant here. For completeness sake nonetheless:
(Behavior is the same for msoFileDialogOpen)
Usage example for the Immediate Window:
Of course, this is only a minor problem but it annoys me nonetheless.
It would probably work to use GetOpenFileNameA, define a hook proc and pass it in the lpfnHook field of the OPENFILENAMEA structure, and send some window message to the text box to make it display the full name. - However, implementing this would be a lot of work for such a "small" problem.
The full file name is: "test_default_file.txt"
This is also the actual content of the control, it just appears truncated. Only the rightmost 18 characters are displayed initially. If you put the focus into that text box and move the caret to the left the full file name appears.
So, the problem is "only" that users are confused because they think, the dialog does not pre-select the intended file name. This is aggravated by the fact that in practice the leftmost 8 characters of the file name are important to identify the correct file.
It doesn't make a difference whether I use the built-in Office file dialog or the GetOpenFileNameA API function.
This is a common problem and you find numerous mentions of it on the internet. However, I wasn't able to find a simple solution to it.
My code is bog standard and IMO mostly irrelevant here. For completeness sake nonetheless:
(Behavior is the same for msoFileDialogOpen)
Code:
Public Function SelectFileOffice(Optional ByVal InitialFileName As String = "") As String
Dim fDialog As Office.FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
Dim fileName As String
With fDialog
.Filters.Add "All Files", "*.*"
If InitialFileName > "" Then
.InitialFileName = InitialFileName
End If
If .Show = True Then
fileName = .SelectedItems(1)
End If
End With
SelectFileOffice = fileName
End Function
? SelectFileOffice("c:\tmp\test_default_file.txt")
Of course, this is only a minor problem but it annoys me nonetheless.
It would probably work to use GetOpenFileNameA, define a hook proc and pass it in the lpfnHook field of the OPENFILENAMEA structure, and send some window message to the text box to make it display the full name. - However, implementing this would be a lot of work for such a "small" problem.