cannot get GetOpenFilename to work

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
 
A

Ardus Petus

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

HTH
 

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