Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Windows Explorer and select a file

Tags:

excel

vba

Is there a way to open a Windows Explorer window from a vba form, navigate to a specific file and select it so that the file name is placed in a text box?

like image 905
Quintis555 Avatar asked Apr 24 '12 19:04

Quintis555


People also ask

How do I select a file in Explorer?

Press Windows key + E to open File Explorer. Press Tab until you're in the section of the window containing the files or folders you want to select. Use the arrow keys to move to the file or folder you want to select.

How do you select a file or folder in Windows Explorer?

Using the Shift and Left Mouse Key Step 1: Launch File Explorer. Step 2: Open the File Folder containing the files to be selected. Step 3: Select any of the files that you need by clicking on it. Step 4: Hold down the Shift key on your keyboard.

How do I select open in Windows Explorer?

By default, File Explorer opens to Quick Access. If you'd rather have File Explorer open to This PC, go to the View tab and then select Options. In the Open File Explorer to list, select This PC, and then select Apply.

How do I open files with File Explorer?

To open File Explorer, click the File Explorer icon on the taskbar, or double-click any folder on your desktop. A new File Explorer window will appear. Now you're ready to start working with your files and folders. From File Explorer, double-click a folder to open it.


1 Answers

Check out this snippet:

Private Sub openDialog()     Dim fd As Office.FileDialog      Set fd = Application.FileDialog(msoFileDialogFilePicker)     With fd        .AllowMultiSelect = False        ' Set the title of the dialog box.       .Title = "Please select the file."        ' Clear out the current filters, and add our own.       .Filters.Clear       .Filters.Add "Excel 2003", "*.xls"       .Filters.Add "All Files", "*.*"        ' Show the dialog box. If the .Show method returns True, the       ' user picked at least one file. If the .Show method returns       ' False, the user clicked Cancel.       If .Show = True Then         txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox        End If    End With End Sub 

I think this is what you are asking for.

like image 185
eabraham Avatar answered Oct 06 '22 01:10

eabraham