+ Reply to Thread
Results 1 to 3 of 3

GetOpenFileName Error

  1. #1
    Registered User
    Join Date
    04-20-2005
    Posts
    7

    GetOpenFileName Error

    I am trying to use the GetOpenFilename function to run a macro on various text files, but when I choose a file, I get the following Error message:

    Run-time error "1004"
    'False.xls' could not be found.

    I have tried researching this, but nothing has worked. This is my code:


    ChDir "C:\Samantha\Month-End In Progress"
    Workbooks.OpenText FileToOpen = Application _
    .GetOpenFilename("Text Files (*.txt), *.txt")
    If FileToOpen <> False Then
    MsgBox "Open " & FileToOpen
    End If

    Can anyone help me with this? I'd really appreciate it.
    Thanks!
    Sam

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481

    GetOpenFileName Error

    You need to separate your GetOpenFilename statement from the OpenText statement.
    So first GetOpenFilename assigns the full path of the text file you want to open.
    Then Workbooks.OpenText operates on that.

    revised code below:

    Sub OpenTxtFile()
    ChDir "C:\Samantha\Month-End In Progress"
    FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    Workbooks.OpenText FileToOpen
    If FileToOpen <> False Then
    MsgBox "Open " & FileToOpen
    End If
    End Sub

    Hope this helps

    B

  3. #3
    Registered User
    Join Date
    04-20-2005
    Posts
    7
    Thank you so much! It worked!!



    Quote Originally Posted by bhofsetz
    You need to separate your GetOpenFilename statement from the OpenText statement.
    So first GetOpenFilename assigns the full path of the text file you want to open.
    Then Workbooks.OpenText operates on that.

    revised code below:

    Sub OpenTxtFile()
    ChDir "C:\Samantha\Month-End In Progress"
    FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    Workbooks.OpenText FileToOpen
    If FileToOpen <> False Then
    MsgBox "Open " & FileToOpen
    End If
    End Sub

    Hope this helps

    B

+ 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