Results 1 to 2 of 2

Thread: msoFileDialogFilePicker not opening as expected
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Nov 2014
    Location
    New Jersey
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default msoFileDialogFilePicker not opening as expected

    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?

  2. #2
    Board Regular
    Join Date
    Mar 2015
    Posts
    3,400
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    7 Thread(s)

    Default Re: msoFileDialogFilePicker not opening as expected

    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 by Yongle; Jun 19th, 2019 at 11:13 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •