msoFileDialogFilePicker not opening as expected

TriAxisZero

New Member
Joined
Nov 15, 2014
Messages
11
I have a simple macro using the file dialog, the problem i'm having is the dialog is not executing the filters when opened.

Code:
Sub GetFieldFile()
Dim Getfile As FileDialog
Dim projnum As String


projnum = "\" & Home.Range("Project_Number").Value & "*.txt"


Set Getfile = Application.FileDialog(msoFileDialogFilePicker)


With Getfile


    
    .Filters.Clear
    .Filters.Add "Field Files", "*.txt;*.csv", 1
    .Filters.Add "Text Files", "*.txt", 2
    .Filters.Add "CSV Files", "*.csv", 3
    .FilterIndex = 1
    .Title = "Select a File"
    .ButtonName = "Import"
    .InitialFileName = "X:\SDSKPROJ\_Dump-" & Format(Now(), "YYYY") & projnum
    .InitialView = msoFileDialogViewDetails
   
    
    
    If .Show = -1 Then
    
        Debug.Print .SelectedItems(1)
        ImportFieldData (.SelectedItems(1))
    
    End If
    
End With


End Sub


When run this sub the dialog opens, filter 1 is active, but is not filtering the file list & the button caption is wrong, reading "Open" instead of "Import".
if i select a file the button caption changes, but the filter is still not working.
If i change the filter it works, including if i change in back to the first filter which should be active when opening.

any ideas?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
the button caption is wrong, reading "Open" instead of "Import".....if i select a file the button caption changes

Agreed - same behaviour on my PC

So I tested
Code:
    .ButtonName = "LongNameThatMakesBiuttonWider"

The button:
- is now wider,
- shows caption "LongNameThatMakesBiuttonWider" (very briefly - less than 1 second)
- immediately changes to "Open"
- changes to "LongNameThatMakesBiuttonWider" when file selected

When run this sub the dialog opens, filter 1 is active, but is not filtering the file list

The filter works correctly (running Excel365 and Windows10)

1 Test what happens if .InitialFileName points at local folder on PC

2 Which version of Excel and Windows are you running?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top