+ Reply to Thread
Results 1 to 4 of 4

Can't open TXT file in VBA

  1. #1
    Registered User
    Join Date
    12-08-2008
    Location
    Sacramento, CA US
    MS-Off Ver
    2007
    Posts
    17

    Can't open TXT file in VBA

    Hello. I need some help. Hopefully it's something simple.

    I am trying to open a txt file, but I get an error message that says

    "Run-time error '52':
    Bad file name or number

    The file name is correct. I tried two ways to pass the name -- as a variable and from Application.GetOpenFilename("Text Files (*.txt), *.txt")

    The line where VBA complains is "Open fileToOpen For Input As #InFile"

    Please Login or Register  to view this content.
    Any help is much appreciated.

    Thank you,

    Angel
    Last edited by verdugan; 12-23-2008 at 08:58 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Angel

    You define InFile as an integer, but you don't put anything into it. So it defaults to 0 which isn't a valid file number.

    Put in a line like
    Please Login or Register  to view this content.
    and see how that goes.

    rylo

  3. #3
    Registered User
    Join Date
    12-08-2008
    Location
    Sacramento, CA US
    MS-Off Ver
    2007
    Posts
    17
    Thank you rylo

    That was the problem. I thought the problem was with the file name.

    Thank you for your help!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    ... or
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

+ 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