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?
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,680
Office Version
365
Platform
Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,096,196
Messages
5,448,893
Members
405,539
Latest member
Phenomi

This Week's Hot Topics

Top