Display an OpenFile Dialog Box

by Linda Quinn

Close Window

The following code can be used to display an OpenFile dialog box.
This allows the user to select the workbook to be processed.

Dim filex As Variant
Dim wkb As Workbook

filex = Application.GetOpenFileName __
   (FileFilter:="microsoft excel files (*.xls), *.xls", __
   Title:="Get File", MultiSelect:=True)

If filex <> false then
Application.Workbooks.Open filex
Set wkb = ActiveWorkbook
mname = DIR(filex)
wkb.SaveAs filename:=hpath + mname
End if


Application.GetOpenFileName will display an open dialog box

FILEX is a variable that will contain the name and path of the selected file.

If a file was not selected, FILEX will be false.

DIR(filex) will return the file name portion of the file in filex.





FileFilters describe which files are displayed in the Open File dialog


Examples of Filter Statements
FileFilter:="Microsoft Excel Files (*.xls), *.xls"
FileFilter:="Text Files (*.txt), *.txt"
FileFilter:="Add-In Files(*.xla), *.xla"
FileFilter:="Text Files (*.txt), *.txt", Add-In Files(*.xla), *.xla"
The above will list both filters in the drop-down box
FileFilter:="Visual Basic Files(*.bas; *.txt), *.bas; *.txt"
Semi-colons separate multiple file types for a single filter type



=================================================================
This content was created by Linda Quinn of LQNet.

See http://www.lqnet.com for a great collection of articles on this and other topics.

=================================================================
Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.


====================================================================
Want an expert to help with your project?    LQ Systems, Inc.   Business Solutions
====================================================================