How to select a specific file type

M

MervB

I have the following button code - how can I modify it so only a single .cvs
file can be chosen?

Private Sub btnETran_Click()
Dim lngCount As Long

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Show

' Display paths of each file selected
For lngCount = 1
MsgBox .SelectedItems(lngCount)
Next lngCount

End With

End Sub

Thanks
 
R

RB Smissaert

Sub btnETran_Click()
Dim lngCount As Long

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.Filters.Add "Text files", "*.txt; *.ini; *.bat", 1
.AllowMultiSelect = False
.Show

' Display paths of each file selected
For lngCount = 1 To 1
MsgBox .SelectedItems(lngCount)
Next lngCount

End With

End Sub

To find this out just use the Object browser.
If you look in the list on the left you will see the FileDialog class with
on the right all the members.
One of them is Filters.
Right-click Filters and look in the help.


RBS
 

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