+ Reply to Thread
Results 1 to 13 of 13

File Search Using Wildcard and User Input

  1. #1
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Exclamation File Search Using Wildcard and User Input

    Good Afternoon all,
    I am attmepting to search for a file based on user input and wildcards. The file I am looking for is saved every 30 minutes with its name based on date and time.

    Example: DateTimecampdata.csv

    The last part of the file name campdata.csv is always the same. I want the file that is run at the end of the day, after 22:00. It is always ran within the same 15 minute window. So the file name will always be Date then whatever time it ran, then campdata.csv. I would like to be able to have the user search by whatever Date they need. I would like an Application.InputBox to pop asking them to enter the date then it would search the directory for that day's EoD file. I tried this code and it would not return any results:

    Please Login or Register  to view this content.
    Any help would be greatly appreciated.
    Last edited by CJPHX; 05-20-2010 at 10:06 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: File Search Using Wildcard and User Input

    Please Login or Register  to view this content.
    change the red formatrule to what has been used in the filenames.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: File Search Using Wildcard and User Input

    Welome to the forum, CJPHX.

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: File Search Using Wildcard and User Input

    Sorry, but I don't understand what you mean by change the red formatrule. The file name right now is saved as "20100518 2233 campdata.csv" with the spaces in the file name.

    Sorry about that SHG.
    Last edited by CJPHX; 05-19-2010 at 05:21 PM.

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: File Search Using Wildcard and User Input

    You might want to look at avoiding filesearch as it was dropped in 2007.

    There a couple of workarounds mentioned here: http://www.mrexcel.com/forum/showthread.php?t=268046

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  6. #6
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: File Search Using Wildcard and User Input

    Quote Originally Posted by Domski View Post
    You might want to look at avoiding filesearch as it was dropped in 2007.
    Dom
    I did look into this Dom, however my company still uses 2003 and from what I was told has no plans of upgrading in the near future. Thank you for the suggestion.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: File Search Using Wildcard and User Input

    colors can't be used between code-tags on this forum.
    Neverthesless.
    My earlier code must do the trick, based on the latest information you gave.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: File Search Using Wildcard and User Input

    First SNB, I want to say thank you for trying to help me with this. Second, I am new to VBA as I jsut started coding in excel this last week. I have left work for the day so I am unsure of the excat error, but I still get a line error and when I debug it, it goes to the .FileName line.

    Please Login or Register  to view this content.
    The only difference in my code is the actual .LookIn line contains the full file directory.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: File Search Using Wildcard and User Input

    This works for me:

    Please Login or Register  to view this content.

    Dom
    Last edited by Domski; 05-20-2010 at 04:57 AM.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: File Search Using Wildcard and User Input

    Take care there is a space between ) en &.

  11. #11
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: File Search Using Wildcard and User Input

    Thanks for the help, however I am getting a Runtime '6' Overflow error on the ".FileName" line.

    This is the exact copy of the code as I have it now in the macro. There are hundreds of files in this directory and there will be approximately 20-30 where the file name starts with YYYYMMDD for each day the only changing variable is the time. It almost seems like is returnign too many options which shouldnt be the case as there would be only one file with the date and time stamp.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: File Search Using Wildcard and User Input

    How are you entering the date?

    You're using Format to convert a date to the text format yyyymmdd so it must be entered as a real date in the first place like 05/18/2010. If you just want to enter the value as 20100518 then you can just use:

    Please Login or Register  to view this content.

    Dom

  13. #13
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: File Search Using Wildcard and User Input

    THANK YOU. Dom as I said I am new to VBA and I didn't even realize that the Format option changed the date to text. I had been entering it as 20100518. However, now that I switched it to the date it
    works perfectly. I can not thank you enough.

+ 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