+ Reply to Thread
Results 1 to 16 of 16

search folder for file

  1. #1
    Registered User
    Join Date
    02-25-2007
    Posts
    34

    search folder for file

    I'm using Excel 2007, so no .filesearch

    I want to search a folder for a file containing a certain phrase. Would like to use a case option like in java.

    search for file containing "aaa", "bbb", "ccc", or "ddd"

    then if file exists

    Please Login or Register  to view this content.
    -I'm not sure the correct syntax for the above.

    This is gonna be a long process to get the code where I want it, but I taking one step at a time, so I understand what is happening and I can change if I need.

    TIA

    Wanted to add that the folder can be set to only have 1 file, but would like to be able to have multiple files while testing.
    Last edited by Jay59; 12-31-2008 at 12:40 PM. Reason: added note

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Does DIR() work in 2007?

    What sort of files are you testing? Excel?

    rylo

  3. #3
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    Yes and they are excel files. Once i get this down, each file has different set of instructions.

    Basically all files are opened and edited with vba code, saved, then imported to access database. After that happens, I open another file that is linked to access database to generate reports, then i copy and past pivot tables to email and send reports that way.

    Right now its 5 a day and another 10 weekly.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Ok so you should be able to use DIR to cycle through the files, open any excel file, cycle through the sheets in the file and do your search(s).

    If all the data is being copied into an access database, then why don't you just extract it from there into excel using SQL. Don't have to work your way through the files. Or do you have to different processing on the files to make them in a shape to put into Access?

    If you can describe in more detail what you are doing, there may be alternative approaches that would simplify things...


    rylo

  5. #5
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    Total of 5 files a day, 3 files have to edited before importing them into access.

    Here is the complete process I hope to implement.

    -Everyday from 7 to 12 in the morning i receive 5 files at least 15 mins apart.
    When the file hits my inbox I have thunderbird(email client) to save it and open with default program.

    So a change of plans i guess, i need this code to run on any file that is opened.(sorry just test this to see how it actually works.)

    -Use a case statement to check the file name and execute code based on what the file name may contain. Its gonna be specific for example Report32145 would have to be in the file name for case 1.( this name will change everyday, but will always contain Report32145.(so i guess search for *Report32145*)

    -After the case statement is used the specified macro is execute on the file, editing it to the requirement format.

    -Save file to specified spot and with specified name.(all this is specified in the vba code to run based on case statement.

    -Close file

    -Then i would use a command after the close statement to open access database and run a macro that imports the file that was just saved.

    -The database would close itself and open another file that refreshes its report.

    -That file use vba to copy and paste date into email and send email.



    I know this will be long process and take some time to setup, but it will be worth it.

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Start with the access part. Create the file import procedure, then create an autoexec macro that will call this sub so that when the database opens, it will automatically import the data.

    See how that goes.

    rylo

  7. #7
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    That part I got, but I need to start at the beginning with running the case when the file opens to execute the desired code.


    And btw, thanks for the help and time.

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Rather than opening the file that has just been saved, can thunderbird open a specific excel workbook?

    rylo

  9. #9
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    As of right now, no. I'm searching alternative email clients to see if I can do this.

  10. #10
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Good luck. If you can find a way to open a particular excel workbook, then things should be reasonably easy from there.


    rylo

  11. #11
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    I'm working on doing this using the plugin for thunderbird, but in the mean time, i'm going to move forward.

    First this will be how to search folder for files containing keywords.

    Since I'm using 2007 i can't use filesearch, so how would I do this.

    Thanks

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    When you say search for key words, do you mean in the filename or in the file's contents?

    If the latter, try the API or ADO methods posted at: http://www.experts-exchange.com/Micr..._23483221.html If you try one of those, let us know what you used and how it worked out for you.

    If the former, there are several ways to do it using the File System Object method or DOS. Here are 2: http://www.vbaexpress.com/forum/showthread.php?t=22245
    Last edited by Kenneth Hobson; 12-19-2008 at 08:16 PM.

  13. #13
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Have you tried dir() in 2007? If it doesn't work, then maybe you will have to post in the 2007 forum to see if someone there knows how to do the file search.

    rylo

  14. #14
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    I accomplished by filling an array with the file names and searching the names in the array. Since my folder will only have the files that I need to work with the file count will be below 10, so this method works fast.

    Please Login or Register  to view this content.
    Last edited by Jay59; 12-31-2008 at 01:05 PM. Reason: Added exit if file count = 0

  15. #15
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Not sure what FileCountA handles. I would suggest that you add code to handle the case where Max=0.

    The dictionary object can be handy for such things. e.g.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    02-25-2007
    Posts
    34
    Thanks

    FileCount returns the number of files in directory.

    Thanks for the suggestion, as of right now I have very little error handling in my code, I'm working on adding it.


    So I'll add
    Please Login or Register  to view this content.
    Last edited by Jay59; 12-31-2008 at 01:04 PM.

+ 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