Microsoft Office Tutorials and References
In Depth Information
The Excel GetOpenFilename Method
Figure 12-8: The GetOpenFilename method displays a dialog box used to specify a file.
The following example is similar to the previous example. The difference is that the user can
press Ctrl or Shift and select multiple files when the dialog box is displayed. Notice that I check
for the Cancel button click by determining whether FileName is an array. If the user doesn’t
click Cancel, the result is an array that consists of at least one element. In this example, a list of
the selected files is displayed in a message box.
Sub GetImportFileName2()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String
‘ Set up list of file filters
Filt = “Text Files (*.txt),*.txt,” & _
“Lotus Files (*.prn),*.prn,” & _
“Comma Separated Files (*.csv),*.csv,” & _
“ASCII Files (*.asc),*.asc,” & _
“All Files (*.*),*.*”
‘ Display *.* by default
FilterIndex = 5
‘ Set the dialog box caption
Title = “Select a File to Import”
‘ Get the file name
 
Search JabSto ::




Custom Search