filefilter in Excel VBA not working as I want

philipb645

New Member
Joined
Sep 26, 2014
Messages
3
I have the following line in my VBA code in Excel 2010

rnl_fname = Application.GetOpenFilenam<wbr>e(Title:="<wbr>Select R560 Renewal SUM", _
filefilter:="R560Combined?<wbr>??.SUM (*.SUM),*.SUM")

When the file dialog box comes up, I only want it to show files that start with R560Combined and end in .SUM. For instance I might have a R560CombinedARD.SUM and a R560ARD.SUM. I only want to see the COMBINED one in my file open dialog. I've tried putting the R560Combined in front of both *.sum and that doesn't work. If I put it in front of the first *.sum, then it defaults to *.* basically and doesn't use my filter. I've tried it without the question marks. Any ideas on how I can make this work?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
.
.

The FileFilter parameter specifies the file filtering criteria (i.e. the extension of the file).

Try something like this as a workaround:

Code:
Sub test()

    Dim fnm As Variant
    Dim txt As String
    
    fnm = Application.GetOpenFilename( _
        filefilter:="SUM Files (*.sum),*.sum")
        
    'exit if dialog box cancelled
    If fnm = False Then Exit Sub
    
    'set text required in fnm
    txt = Application.PathSeparator & "R560Combined"
        
    'exit if fnm does not contain txt
    If InStr(fnm, txt) = 0 Then Exit Sub
    
    '
    '
    ' more code goes here...
    '
    '
    
End Sub
 
Upvote 0
Thanks for the suggestion but it still shows me both file names in my open dialog. I can do this very simply in .Net, but in here it doesn't seem to work the same way.
 
Upvote 0
.
.

It will still show other .sum files in the dialog box, but if the user selects a filename that doesn't begin with "R560Combined" then the subsequent lines will pick this up...
 
Upvote 0
That's what I am trying to prevent. I don't want the file open dialog box to even show that. I'm trying to filter that so it only shows files that start with R560Combined*.sum
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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