+ Reply to Thread
Results 1 to 5 of 5

How to apply a filter on Application.FileDialog?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    How to apply a filter on Application.FileDialog?

    Hello,

    I have the following subroutine which enables me to select a file on my C drive. However, when it shows the files, I would like it to
    only show the files that are of ".txt" file type and hide the rest.

    Here's the code:

    Sub SelectFiles()
        'Declare a variable as a FileDialog object and create a FileDialog object as a File Picker dialog box
        Dim iFileSelect As FileDialog
        
        Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)
        Dim vrtSelectedItem As Variant
        
            If iFileSelect.Show = -1 Then
                
                For Each vrtSelectedItem In iFileSelect.SelectedItems
                    MyPath = vrtSelectedItem   ' MyPath will have the filename the program is exported to
                Next vrtSelectedItem
            End If
            
        Set iFileSelect = Nothing
    End Sub

    What would have to be modified in the above code for the dialog box to show only the .txt file types?

    thanks all for help!
    rn

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: How to apply a filter on Application.FileDialog?

    You may add these two lines of code before the If statement....
    iFileSelect.Filters.Clear
    iFileSelect.Filters.Add "Text Files", "*.txt"
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: How to apply a filter on Application.FileDialog?

    wow!

    Thanks sktneer!

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: How to apply a filter on Application.FileDialog?

    You're welcome.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: How to apply a filter on Application.FileDialog?

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] can't seem to use application.filedialog twice
    By timmatthews in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2013, 10:34 AM
  2. Replies: 1
    Last Post: 07-11-2013, 05:01 PM
  3. Abort Options for Application.Filedialog
    By RoyMakaay1985 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2009, 07:39 AM
  4. Application.FileDialog(msoFileDialogOpen) and error 75
    By H.A. de Wilde in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2006, 08:57 PM
  5. Application.FileDialog(msoFileDialogOpen)
    By H.A. de Wilde in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2006, 04:55 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1