+ Reply to Thread
Results 1 to 8 of 8

Open files in folder by keyword, use wildcard *

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Durham, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Open files in folder by keyword, use wildcard *

    Hello, I want to open all excel files in a folder on SharePoint that include the words "Detail Form" in the filename. I can get my code to work if I hard-code the filenames, but the wildcard isn't working. Here is what I'm trying to use right now:

    Please Login or Register  to view this content.
    The DeptFolder variable works, but as soon as I add a wildcard instead of the full filename, I get errors.

    Thanks in advance for your help.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Open files in folder by keyword, use wildcard *

    More code is needed to make the wildcard applicable. Using the DIR() method is a common way to cycle through all the files in a particular folder using wildcards, like so:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Durham, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Open files in folder by keyword, use wildcard *

    Wow that is great, thanks a lot for your help!

  4. #4
    Registered User
    Join Date
    10-01-2009
    Location
    Durham, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Open files in folder by keyword, use wildcard *

    Sorry, I should have tried the code before I said something...

    I am doing something wrong with the Dir() command. I consistently am getting a "Bad file name or number" error when using Dir(). I wrote the following sample script to illustrate my problem. The WB will open, so clearly the path and filename are correct, but then when I get to DirTest, it breaks and gives the error message.

    Please Login or Register  to view this content.
    I really appreciate any help, and will refrain from saying something is working until I have actually tried it...

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Open files in folder by keyword, use wildcard *

    Use the first method. I don't know that the DIR() call will actually pass to the internet, and since the first syntax works and solves your problem, don't fret the time one the DIR() method. Save that for when you want to cycle through many files in a local folder.

  6. #6
    Registered User
    Join Date
    09-21-2009
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Open files in folder by keyword, use wildcard *

    I've got a similar, (I think) simpler query... (should I post this elsewhere? i.e. not on a solved thread?)

    I have a file, which is always saved with the same name in the same directory folder, however it is routinely updated and renamed as a new version with relevant date i.e. "FILE_NAME_vxx_DD-MM-YYYY"... the older versions are dragged to a superseded folder, so they won't interfere with a search performed in the main folder.

    I've set up a toolbar that has a Macro which opens the file (as I work on it a lot) but whenever the file name changes I have to update the Macro to reflect the new version number and date....

    So I'm after some code that will find: FOLDER/FOLDER/FOLDER/FILE_NAME*

    where * represents the varying version/date text... I've had a tinker with the code above but don't fully understand what I'm doing - anyone able to sort this please?

    Thanks JP

    My attempt:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Open files in folder by keyword, use wildcard *

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  8. #8
    Registered User
    Join Date
    10-31-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Open files in folder by keyword, use wildcard *

    Quote Originally Posted by JBeaucaire View Post
    More code is needed to make the wildcard applicable. Using the DIR() method is a common way to cycle through all the files in a particular folder using wildcards, like so:
    Please Login or Register  to view this content.
    Thank you for this great script. It is short and simple. It has helped me tremendously.

    The line Workbooks.Open wbName does not work for me. I have to change it to Workbooks.Open (MyPath & wbName).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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