+ Reply to Thread
Results 1 to 6 of 6

Open file with a specific string in the filename

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Jaipur - India
    MS-Off Ver
    Excel 2007
    Posts
    3

    Open file with a specific string in the filename

    I am trying to open a specific file from the same folder which contains the macro enabled sheet using the following code:

    Workbooks.Open (ThisWorkbook.Path & "\abc xyz_dd_mm_yy.xlsx")

    Now, every week the dd_mm_yy section of the file name will change and "abc xyz" portion will remain the same. Is there a way, that I can open any file which contains "abc xyz" in the filename using VBA?

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Open file with a specific string in the filename

    vikas.mehta80,

    Welcome to the forum!
    Will there always only be a single file that contains "abc xyz"? Or could there be multiple files? If there are multiple files, do you only want to open the most recent, or all of them?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    09-18-2012
    Location
    Jaipur - India
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Open file with a specific string in the filename

    There will be only one file with the name "abc xyz" in the folder.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Open file with a specific string in the filename

    vikas.mehta80,

    If there is always only one file, you should be able to adapt the following code. I have provided comments for clarity.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-18-2012
    Location
    Jaipur - India
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Open file with a specific string in the filename

    Thanks a lot it works fine

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Open file with a specific string in the filename

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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