Tech Support Guy banner

Excel VBA set a filter for a exact filename using MsoFileDia

1298 Views 1 Reply 1 Participant Last post by  Keebellah
Hi guys,
I've been plying around with this code but cannot achieve what I want:

Code:
Private Sub openDialog()
    Dim txtFileName As String
    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 (macro)", "*.xlsm"
      .Filters.Add "Excel", "*AdminMEDEWERKER.xlsm"
      ' 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
It's the red line that I am trying to use as filter.
I know how this works and yes I can add code to check if the correct file was selected, but that's not it.
I want the filetr to only show the AdminMEDEWERKER.xlsm when a folder is selected.
The problem lies in the part in red, if I place *.xlsm it will show all xlsm files.

Code:
.Filters.Add "Excel","*AdminMEDEWERKER.xlsm"
Anybody an idea?
I also placed this question on the Excel VBA forum
https://forums.techguy.org/threads/...or-a-exact-filename-using-msofiledia.1238235/
See less See more
Status
Not open for further replies.
1 - 2 of 2 Posts
Solved it (https://www.excelforum.com/excel-pr...exact-filename-using-msofiledialogpicker.html)
sample file for those who might be interested, it does what I specifically needed it to do

Attachments

1 - 2 of 2 Posts
Status
Not open for further replies.
Top