+ Reply to Thread
Results 1 to 3 of 3

cannot get GetOpenFilename to work

  1. #1
    scotgotchi
    Guest

    cannot get GetOpenFilename to work

    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


  2. #2
    Ardus Petus
    Guest

    Re: cannot get GetOpenFilename to work

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

    HTH
    --
    AP

    "scotgotchi" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > 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
    >




  3. #3
    scotgotchi
    Guest

    Re: cannot get GetOpenFilename to work

    Thanks very much Ardus.
    So Simple!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1