+ Reply to Thread
Results 1 to 18 of 18

file not found

  1. #1
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    file not found

    I am using the following line of code to provide the brousing window to locate a file.

    PHP Code: 
    FName Application.GetOpenFilename("Excel Files,*.xls"1"Select all files", , False
    The program then continues on until

    PHP Code: 
    Workbooks.OpenText FileName:=FName 
    where I am getting an error

    Run time error 1004

    D:\......\filename.xls could not be found.

    why would this be?
    Last edited by dgkindy; 04-24-2009 at 09:22 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: file not found

    Please take a couple of minutes and read ALL theForum Rules then wrap your VBA code (Rule 3)
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Change your code as below and that should open up the workbook.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    Still same error. I have include a bit more code just to make sure there is something I am doing wrong somewhere else

    PHP Code: 
    Sub DesignReviewForm()
        
    Dim Folders() As String
        Dim FName 
    As String
        Dim filesavename  
    As String
        Dim X 
    As Integer
     
        MoveUp 
    2
        Count 
    0
     
        Call DesignReviewHarvest
     
     
        Application
    .ScreenUpdating False
        Application
    .DisplayAlerts False
     
        
    'Open file selection menu
        FName = Application.GetOpenFilename("Excel Files,*.xls", 1, "Select all files", , False)
        If TypeName(FName) = "Boolean" Then
                MsgBox "You didn'
    t select a file"
                Exit Sub
        End If
     
        Workbooks.OpenText FName 

  5. #5
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Do you still get the same file not found error.

    Secondly i assume you are pressing the open button and not the cancel.
    and can you confirm if you have a file open routine in Call DesignReviewHarvest or not

  6. #6
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    Still getting the same error
    Run-time error '1004':

    'D:\......xls' cound not be found. Check the spelling of the file name, andd verify that the file is correct.

    If you are trying to open the file from your list fo most recently used
    It then gets cut off.

    I confirmed I am selecting the open button. Good to always check.

    DesignReviewHarvest is a routine that is just collected data from various locations on a spreadsheet.

  7. #7
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    The default path of excel may have changed, so make sure both the workbooks are in same folder. Then use
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Just to check include this line
    Please Login or Register  to view this content.
    to check you get the full file path and not jsut the name

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: file not found

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    Excel_1982 has the winning suggestion but still have not won the war.

    I have determined that the function works if the file that I want to open is in the same location as the original file.

    I used the Thisworkbook.path but then it only give me the path and parses the file name off.

    Stuck again

  11. #11
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Can you place the code change you made here and also indicate what does Applcation.path returns. Maybe you need to concatanate the path of file to what Applciation.path returns.

  12. #12
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    If this code is giving me the correct address, why would it not open the file with the workbooks.open command?

    PHP Code: 
        FName Application.GetOpenFilename("Excel File,*.xls"1"Select file", , False
    Is there a need to string together the address when I already have it.

    All I can say is that if I put the file in the same location as the original file, it works but that obviously defeats the perpose of having folder.

    The new bit of code just gives me the address to the desktop however not the full address to where the new file is located.

    PHP Code: 
    Sub DesignReviewForm()
        
    Dim Folders() As String
        Dim FName 
    As Variant
        Dim filesavename  
    As String
        Dim X 
    As Integer
        
        MoveUp 
    2
        Count 
    0
        
        Call DesignReviewHarvest
        
        
        Application
    .ScreenUpdating False
        Application
    .DisplayAlerts False
            
        
    'Open file selection menu
        FName = Application.GetOpenFilename("Excel File,*.xls", 1, "Select file", , False)
        If TypeName(FName) = "Boolean" Then
                MsgBox "You didn'
    t select a file"
                Exit Sub
        End If
        
        Workbooks.Open ThisWorkbook.Path & FName
        Workbooks.Open FName 

  13. #13
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Do you get correct path to the file if you just say
    Please Login or Register  to view this content.
    It works fine for me. It might just be that your excel path have changed.
    Last edited by excel_1982; 04-24-2009 at 11:56 AM.

  14. #14
    Registered User
    Join Date
    04-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: file not found

    Another suggestion, make sure the file you are selecting is a valid xls file and also that it doesnt contain spaces.

  15. #15
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    Yes, the correct location is displayed

    This is the file location and file name:

    D:\Documents and Settings\414004425\Desktop\3237949 - Ralston Foods\ISO Document Templates\Design Review, Handoff, and Checklist Requirements (302-050-002)\Design Review, Handoff, and Checklist Requirements (302-050-002C).xls

  16. #16
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: file not found

    Fname has the full path already. Adding another path makes no sense.

    Spaces should be no problem.

    This works for me.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    Re: file not found

    I pasted your version of the code into the file and still get the same error.

    But you say that this code works for you on your computer?

    Did you select a file from another directory other then the one that your test file was in?

  18. #18
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: file not found

    Yes, it always worked as expected.

+ 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