+ Reply to Thread
Results 1 to 15 of 15

Opening file with file path and partial name

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Opening file with file path and partial name

    I have a Macro that opens specific workbooks, copies data from them, and pastes it into a master workbook. The problem is that the names of the workbooks I need to open will constantly change; however, the last few letters will always be the same. For example, I will have workbooks 130058_IP.csv 130059_IP.csv

    I was wondering if there is a way to open a workbook using its file path and "_IP.csv"

    ANy help would be great!

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Opening file with file path and partial name

    the workbook with macro must be in the same folder of csv files, otherwise you have to change .InitialFileName
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    Thanks, is there a way to open it without prompting the user to do so?

  4. #4
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Opening file with file path and partial name

    I found this works for me. (But doesn't if I try and do it all in one line of code.)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    It prompts an error saying it can't open it because it's read only or encrypted but I know its not.

  6. #6
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Opening file with file path and partial name

    I don't know why that is.
    Is there more than 1 file that fits the name?

  7. #7
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    well there's an _IP-STATS but I changed the file name to _IP-STATS so there would be no chance of a duplicate file but it still gave the same error

  8. #8
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    The weird thing is that the error says excel cannot access '130058'. The document may be read only or encrypted

  9. #9
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Opening file with file path and partial name

    If you step through the code in the editor using F8 then hover over the filename what filename do you see?

  10. #10
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    it says it's empty, the filePath is there though

  11. #11
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Opening file with file path and partial name

    I don't know how much coding you do so don't be offended by stupid questions/suggestions.

    Initially it will be empty. Step through to the Workbooks.Open line with F8 and then hover over the filename on the previous line. If it's still showing "" then it hasn't found a matching file in the directory.

  12. #12
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    Yeah I did and it's still showing empty. The file is there though so why is it saying empty. Could it be something with the syntax you used for
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Opening file with file path and partial name

    OK I get the warning you stated previously re: encrypted/read only if I omit the last backslash in the filepath.

    it must be "C:\junk\" <---backslash.

  14. #14
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening file with file path and partial name

    I'm using a different path which doesn't have a backslash at the end it still doesn't work

  15. #15
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Opening file with file path and partial name

    with path need backslash, otherwise you can not solve

+ 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