cannot get GetOpenFilename to work

  • Thread starter Thread starter scotgotchi
  • Start date Start date
S

scotgotchi

Could someone please take a look at this bit of code and tell me what's
wrong with it - I'm stumped, I've tried various things and just cannot
get it to work. I'm using Windows XP and Office 2003 .
Ultimately, I'll want it to default to a network drive, but I can't
even get it to work when starting on C:\. I get a runtime error 1004
which I believe is "file not found".

Sub myOpenFileDialog()
'
' myOpenFileDialog Macro
'
myFilt = "Text Files (*.txt), *.txt" & _
"Comma Separated Values (*.csv), *.csv" & _
"Excel Workbooks (*.xls), *.xls" & _
"All Files (*.*), *.*"
myFilterIndex = 4
myTitle = "Select Data File to Open"

ChDrive "C:\"
ChDir "C:\"
' Get the file name
myDataFileName = Application.GetOpenFilename(FileFilter:=myFilt, _
FilterIndex:=myFilterIndex, Title:=myTitle)

' Exit if user cancels dialog box
If myDataFileName = False Then
MsgBox "No file Selected"
Exit Sub
End If

' Show myDataFileName Result
MsgBox "Data Filename = " & myDataFileName

End Sub
 
FilterIndex needs comma-separated values:
myFilt = "Text Files (*.txt), *.txt," & _
"Comma Separated Values (*.csv), *.csv," & _
"Excel Workbooks (*.xls), *.xls," & _
"All Files (*.*), *.*"

HTH
 
Back
Top