+ Reply to Thread
Results 1 to 9 of 9

Opening a file with only a partial file name

  1. #1
    Registered User
    Join Date
    07-14-2004
    Posts
    27

    Opening a file with only a partial file name

    I am trying to open a file with only a partial file name being entered thru an input box

    One user will create the file and save it. The file name is created by pulling data from 3 different worksheet cells - i.e. - number, location and name.

    A second user will try to open that file by entering only the number portion of it.

    There are no duplicate file names in the directory where the file is located, so when User2 enters the number, it will only find one file. I have done the reading on "File.Open", but do not want a dialog box to open. I would like this to happen automatically once User2 enters the number.

    Is this possible?

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    You can try to use Dir instruction, for example:
    Please Login or Register  to view this content.
    where myPartialName is the number portion of the file.
    That instruction will return the first file name in case it founds more than one file.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    07-14-2004
    Posts
    27
    Thanks! at least now the msgbox(just for testing) is returning the correct file name. I do get a "Run-time error '1004': application-defined or object-defined error. and I'm pretty sure my syntax on the OPEN line is correct? or am I going crazy?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-14-2004
    Posts
    27
    Ok, so now it seems to work, but it is opening a NEW workbook called file_to_open, not opening the one that it finds. why is it driving me crazy?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302
    The DIR function returns just the plain filename with no path information. So, you need to put the path back in when you open the workbook. I suggest:

    Please Login or Register  to view this content.
    FrankBoston is the pen name for Andrew Garland, Lexington MA

  6. #6
    Registered User
    Join Date
    07-14-2004
    Posts
    27
    THANK YOU!!!!!!!!! You have no idea how crazy I have been going to get it right!!!! Thanks you again!!!

  7. #7
    Registered User
    Join Date
    03-02-2013
    Location
    San Diego
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Opening a file with only a partial file name

    Hello, first time ever posting on a forum.
    Can this be used in an excel worksheet to link/open an external PDF where the first character of the PDF file name are stored in, say for example, cell A3, and the rest of the file name can vary?
    =HYPERLINK("./test folder path/" & A3 & "*.pdf")

  8. #8
    Registered User
    Join Date
    03-02-2013
    Location
    San Diego
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Opening a file with only a partial file name

    I know this is pretty hokey, but I took a stab at it (3 columns back is a formula that pumps out the correct path)


    Please Login or Register  to view this content.
    Last edited by arlu1201; 03-02-2013 at 06:23 AM.

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Opening a file with only a partial file name

    skalumba,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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