Open instance of Windows File Explorer from VBA using filter

Rick Rudolph
Rick Rudolph used Ask the Experts™
on
Using MSAcess VBA  to open Windows File Explorer in a specific folder with a specific filter. Online I see many instances of generating a file picker, that is not what I want. I Want the list of files to be displayed within Windows File Explorer as if I had manually filtered it.

The attached file shows the VBA code that I have so far...........basically I have the filter created and now I need to add the code to open Windows Explorer with the filter.
RO_Image_List.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
I'm not sure I understand the purpose of opening the file dialog.  You either need to open it to either save a file, or open (select a file, or multiple files).  Although you don't actually have to implement code to save or open the file.

Which of these do you want to perform?

You can apply filters to the Open (msoFileDialogFilePicker) but cannot do so with the the Save (msoFileDialogSaveAs) operation.

Sample code for selecting a file:

Dim fDialog As FileDialog, result As Integer
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    
'Optional: FileDialog properties
fDialog.AllowMultiSelect = False
fDialog.title = "Select a file"
fDialog.InitialFileName = "C:\"

'Optional: Add filters
fDialog.Filters.Clear
fDialog.Filters.Add "Access files", "*.md*,*.accd*"
fDialog.Filters.Add "Excel files", "*.xlsx"
fDialog.Filters.Add "All files", "*.*"

'Show the dialog. -1 means success!
If fDialog.Show = -1 Then
   Debug.Print fDialog.SelectedItems(1)
End If

Open in new window

You can also select multiple files by placing this line before line 15 in the previous code segment.
fDialog.AllowMultiSelect = True

Open in new window

John TsioumprisSoftware & Systems Engineer
Commented:
If you want to Open Windows Explorer here is an example:
http://vbadud.blogspot.com/2009/01/how-to-windows-explorer-using-vba.html?m=1

Author

Commented:
Dale,

In answer to your question, I have no idea what the user will be doing with the files when they see the windows file explorer list. They may just be interested to see if a certain file exists, or they may want to open it. In every case, if they want to open a file, they will use the default Windows Program to open the file.......so they will double click on the file in which they are interested.


So I have not had an opportunity to review what John has recommended, it  does however on the surface sound a little more in line with what I need to provide.

I already have a solution for picking files to either save or pass back to the executing function.

Thx,

Rick
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
If all you are interested in doing is allowing the user to open Windows Explorer from within the application, then John's solution (shelling out to Explorer.exe) should work.

shell("C:\Windows\explorer.exe")

Open in new window

Author

Commented:
Thanks for the help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial