• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter file name in Application.FileDialog(msoFileDialogFilePicker)

Costas

Member
Hi Chandoo,

I'm trying to filter the file name to contain a specific string so it only shows files that have this string.
When I try it I get a run-time error 5, invalid procedure call or argument

Here is my code:
Code:
Public MyFullPath as String
Public Const MyLocation As String = "SYD"

Sub FileOpenDialogBox()

    With Application.FileDialog(msoFileDialogFilePicker)
          'Makes sure the user can select only one file
          .AllowMultiSelect = False
          .Filters.Add "Excel files", MyLocation & "*.xlsx;  *.xls", 1
          .Show
          MyFullPath = .SelectedItems.Item(1)
      End With
          Workbooks.Open FileName:=MyFullPath
          MyFileName = ActiveWorkbook.Name

End Sub
Any ideas where I'm going wrong?

Thanks
Costas
 
Last edited by a moderator:
Hi guys,

You are both right. The .filters.add only filters the file extension and it's in the .InitialFileName that you can filter on the file name.

Thank you very much for your help!
 
Back
Top