Is there a way to control a FileDialog in VBA so that the cursor moves to the top of the File List in an open FileDialog? (The cursor always seems to be in the File name control of the FileDialog.)
I would like to use the down arrow key to move through the list of files in the initial folder of an open FileDialog. (Rather than use the mouse to select a file in the File List.)
Hitting the TAB key 10 times moves the cursor to the top of the list, but I would like to automate that process. Best as I can tell, I cannot use SendKeys - either before .Show or after. So I do not think I can pass {TAB} as a keystroke programmatically.
I am writing the code in Outlook but need to use Excel because Outlook does not support the FileDialog.
This is taken from a larger function.
'Launch File Browser
'NOTE: Outlook actually does NOT support the FileDialog, so you need
' to hack a solution and use another Office app instead
'This uses Excel to open the FileDialog
Dim xlobj As Excel.Application
Set xlobj = New Excel.Application
With xlobj.FileDialog(msoFileDialogFilePicker)
.InitialFileName = strStartFolderPath
.Filters.Add "All files", "*.*"
.Title = "Please Select a File to Attach"
.AllowMultiSelect = True
' Try SendKeys Here? - Does NOt work
SendKeys "{TAB}"
.Show
' Try SendKeys Here? Does NOT Work because VBA waits for FileDialog
'SendKeys "{TAB}"
For i = 1 To .SelectedItems.Count
varSelectedItem = .SelectedItems(i)
objItem.Attachments.Add varSelectedItem
Next i
End With
xlobj.Quit
Set xlobj = Nothing
Set myItem = Nothing
Set objItem = Nothing
Set myolapp = Nothing
The dialog is, by definition, a blocking call - so you can't SendKeys
after invoking .Show
and before the user closes the dialog, because the next instruction to run after .Show
will be running after the dialog has closed.
Hitting 10x Tab to get to the list box control seems overkill to me though.
I'm sure your user will be happy to learn that they can cycle the controls in the opposite direction by holding down the Shift key; here I can get to the list box control by pressing Shift+Tab twice.
Other than that, you could put up an Excel UserVoice suggestion to get Microsoft to change that behavior, but I wouldn't hold my breath on that one.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments