Share via

Variable File Dialog Filter

Anonymous
2013-05-21T15:29:09+00:00

I'm trying to use the following code and am getting an error on the Filters.add line

    With Application.FileDialog(msoFileDialogFilePicker)

        .Title = "Select Checklist to Import"

        .InitialFileName = STRDEFAULTDIRECTORY

        .InitialView = msoFileDialogViewList

        .Filters.Clear   '1/24/2012  Barb Reinhardt

        .Filters.Add "Excel Files", myFilter      

        .ButtonName = "Add Checklist"

        If .Show = -1 Then

            txtChecklistFile.Value = .SelectedItems(1)

        Else

        End If

    End With

if myFilter = "*.xls*", I have no issues, however if I define myFilter to be "*6300*.xls*", I get error 5 (Invalid procedural call or argument) in procedure.  

I'm sure it's something silly, but I just don't see it.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-05-21T16:06:36+00:00

You can only add filters of the type *.extension.

If you want to impose restrictions on the file name, use Application.FileDialog(msoFileDialogOpen) and specify the InitialFileName argument, for example:

...

    myFilter = "*.xls*"

    With Application.FileDialog(msoFileDialogOpen)

         .Title = "Select Checklist to Import"

         .InitialFileName = "*6300*.xls*"

         .InitialView = msoFileDialogViewList

         .Filters.Clear   '1/24/2012  Barb Reinhardt

         .Filters.Add "Excel Files", myFilter

...

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-05-21T16:28:43+00:00

    Thanks.   That confirms what I found.

    Was this answer helpful?

    0 comments No comments