Open File showing only Excel files

T

Todd Huttenstine

hey guys I want to be able to bring up an open file dialog
box that only looks for all microsoft excel type files.
You know how when you click open it has that option for
files of type. Thats the kind of thing I want to
automatically happen. What is the code for this?

I also have been using the Browse for folder code Chip
Pearson gave me below:
FName = BrowseFolder("Select a Workbook", "\\")
If FName = "" Then
GoTo SelectWorkbook
Else
'ComboBox.Value = FName
End If


Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const MAX_PATH As Long = 260

Function BrowseFolder(Optional Caption As String, _
Optional InitialFolder As String) As String

Dim SH As Shell32.Shell
Dim F As Shell32.Folder

Set SH = New Shell32.Shell
Set F = SH.BrowseForFolder(0&, Caption,
BIF_RETURNONLYFSDIRS, _
InitialFolder)

If Not F Is Nothing Then
BrowseFolder = F.Items.Item.path
End If

End Function

Is there anyway with this code to show excel file types?

Thank you
Todd Huttenstine
 
C

Chip Pearson

Todd,

The code you posted is for selecting a folder, not a file. You
can't use that code to select a file. Instead, use
GetOpenFilename. E.g.,


Dim FName As Variant
FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls)")
If FName = False Then
MsgBox "You didn't select a file"
Else
MsgBox "You selected: " & FName
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
J

Jean-Yves

Hi Tod,

You could use :
a = Application.GetOpenFilename
Search iin help on GetOpenFilename, you can adjust to restrict only to xl
files
 

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