.GetOpenFilename - Filter on File Name

C

Chris

Hi,

Is there a way to filter the "File Name" when I use the .GetOpenFilename
dialog?
I'd like it to open to a folder, and then filter on text files with
"Monthly_Table_*.txt"
(I know I can filter on the ".txt" files, but I'd like to filter on the file
names too)

Thanks in advance for any pointers.
Chris
 
B

Bob Phillips

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = "*mystring*.xls"

If .Show = 1 Then

MsgBox .SelectedItems(1)
End If
End With
 
J

Jacob Skaria

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = "Monthly_Table_*.txt"
.Show
strFile = .SelectedItems(1)
End With

If this post helps click Yes
 
C

Chris

Thanks very much Jacob, very useful and thanks for the promptness.

One further thing I discovered thats causing a wobbly, is the file is not a
text file; its a .dat file.

Therefore it doesn't show. I've tried all categories but nothing seemed to
work.

Any chance you might know how this is resolved?

If not, no problem, you've already given me a good solution that I can work
around with, so thanks again.
 
R

Rick Rothstein

I've added just one line to Jacob's code (the .Filters line)... this adds a
".dat" item to the selection list; the 1 at the end makes it the first item
in the list. I also changed the default file name's extension to ".dat".

Dim strFile As String
With Application.FileDialog(msoFileDialogOpen)
.Filters.Add "Dat Files", "*.dat", 1
.AllowMultiSelect = False
.InitialFileName = "Monthly_Table_*.dat"
.Show
strFile = .SelectedItems(1)
End With
 
J

Jacob Skaria

Thanks Rick for the follow up.

Rick Rothstein said:
I've added just one line to Jacob's code (the .Filters line)... this adds a
".dat" item to the selection list; the 1 at the end makes it the first item
in the list. I also changed the default file name's extension to ".dat".

Dim strFile As String
With Application.FileDialog(msoFileDialogOpen)
.Filters.Add "Dat Files", "*.dat", 1
.AllowMultiSelect = False
.InitialFileName = "Monthly_Table_*.dat"
.Show
strFile = .SelectedItems(1)
End With

--
Rick (MVP - Excel)




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top