+ Reply to Thread
Results 1 to 3 of 3

Code can't locate filename

  1. #1
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    316

    Unhappy Code can't locate filename

    The following code fails to locate the filename path specified returning "file not found" error. There is surely a file named "tester'" in C:\ Mydocuments folder. What gives? TIA


    Sub Import_TextFiles1()
    Dim RwIndx As Integer
    Dim ColIndx As Integer
    Dim WholeLine As String
    Dim Fname As String

    Application.ScreenUpdating = False
    ColIndx = ActiveCell.Column
    RwIndx = ActiveCell.Row
    Fname = "C:\My Documents\tester.doc"
    Open Fname For Input Access Read As #1
    While Not EOF(1)
    Line Input #1, WholeLine
    Cells(RwIndx, ColIndx).Value = WholeLine
    RwIndx = RwIndx + 1
    Wend
    Close #1
    Application.ScreenUpdating = True

  2. #2
    Kassie
    Guest

    RE: Code can't locate filename

    Hi davidm

    You My documents folder does not branch off C:\ directly

    The correct path is C:\Documents and Settings\username\My Documents. Just
    add your username to the line, and it should pick up
    --
    [email protected]ve_2nd_at. Randburg, Gauteng, South Africa


    "davidm" wrote:

    >
    > The following code fails to locate the filename path specified
    > returning "file not found" error. There is surely a file named
    > "tester'" in C:\ Mydocuments folder. What gives? TIA
    >
    >
    > Sub Import_TextFiles1()
    > Dim RwIndx As Integer
    > Dim ColIndx As Integer
    > Dim WholeLine As String
    > Dim Fname As String
    >
    > Application.ScreenUpdating = False
    > ColIndx = ActiveCell.Column
    > RwIndx = ActiveCell.Row
    > Fname = "C:\My Documents\tester.doc"
    > Open Fname For Input Access Read As #1
    > While Not EOF(1)
    > Line Input #1, WholeLine
    > Cells(RwIndx, ColIndx).Value = WholeLine
    > RwIndx = RwIndx + 1
    > Wend
    > Close #1
    > Application.ScreenUpdating = True
    >
    >
    > --
    > davidm
    > ------------------------------------------------------------------------
    > davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
    > View this thread: http://www.excelforum.com/showthread...hreadid=387955
    >
    >


  3. #3
    Rob Bovey
    Guest

    Re: Code can't locate filename

    "davidm" <[email protected]> wrote in
    message news:[email protected]...
    > The following code fails to locate the filename path specified
    > returning "file not found" error. There is surely a file named
    > "tester'" in C:\ Mydocuments folder. What gives? TIA


    Hi David,

    If the error message tells you there's no such file then I would guess
    there is no such file. Add the following lines of code to verify the
    existence of your file prior to opening it:

    If Len(Dir$(Fname)) = 0 Then
    MsgBox Fname & " could not be located.", vbCritical, "Error!"
    Exit Sub
    End If

    If you see the error message then the file is not there.

    --
    Rob Bovey, Excel MVP
    Application Professionals
    http://www.appspro.com/

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    http://www.appspro.com/Books/Books.htm

    "davidm" <[email protected]> wrote in
    message news:[email protected]...
    >
    > The following code fails to locate the filename path specified
    > returning "file not found" error. There is surely a file named
    > "tester'" in C:\ Mydocuments folder. What gives? TIA
    >
    >
    > Sub Import_TextFiles1()
    > Dim RwIndx As Integer
    > Dim ColIndx As Integer
    > Dim WholeLine As String
    > Dim Fname As String
    >
    > Application.ScreenUpdating = False
    > ColIndx = ActiveCell.Column
    > RwIndx = ActiveCell.Row
    > Fname = "C:\My Documents\tester.doc"
    > Open Fname For Input Access Read As #1
    > While Not EOF(1)
    > Line Input #1, WholeLine
    > Cells(RwIndx, ColIndx).Value = WholeLine
    > RwIndx = RwIndx + 1
    > Wend
    > Close #1
    > Application.ScreenUpdating = True
    >
    >
    > --
    > davidm
    > ------------------------------------------------------------------------
    > davidm's Profile:
    > http://www.excelforum.com/member.php...o&userid=20645
    > View this thread: http://www.excelforum.com/showthread...hreadid=387955
    >




+ 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