How can I put the cursor in the File List of an open FileDialog?

DGP

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
Mathieu Guindon

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I open the file in arrayadapter list after clicking?

How can I open a file and append an item to an existing list in Python

How can I add a text from a list to open a file?

How can I save cursor to file .cur?

How i can open (.it) file?

How can I put cursor on every line in Sublime Text?

how can i retrieve a list of currently open workbooks and get VBA to put them in a mulitple choice dialouge box?

How can i put this into a list comprehension

how can i put for loop for this given list?

How can I put these numbers in list?

After using Application.FileDialog(msoFileDialogFilePicker), how can I save that selected file to a predetermined path?

How can I put a downloadable file into the HttpServletResponse?

How can I put interface in a seperate file?

How can I put a CSV file in an array?

How can I put a user in the superusers file?

tkinter.filedialog open file and savefile methods . How to choose?

How can I put the result of a calculation to be put in a list?

How do I check if the Selecteditems from Filedialog is already open by user?

I have a list of files, how can I open and copy the contents of each file to a new one using bash?

How can I open a linux file in php?

How can I (literally) open a file with Node?

How can I open a file in a new tab?

What is a .txt~ file and how can I open it?

How can I open a .dmg file?

How can I open/convert a .wpostx file?

How can I open a .nsi file?

How can I open file with modifiable on

What is a " .desktop" file? How can I open it?

How can I open a file in C?