+ Reply to Thread
Results 1 to 16 of 16

Searching through multiple excel files

  1. #1
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Searching through multiple excel files

    Hello everyone.

    I need a program which searches a particular string through multiple (all) excel files in a folder.
    I want to have the results (maybe on a page in excel) with:
    -name of the file
    -sheet in the file
    -cell in the sheet (address)
    -cell in the sheet (content)

    I am particularly looking for a VBA solution, but I do not want to open the files before searching, because some of the files take a lot of time to load and the files are big so... there could occur a memory shortage.

    I would appreciate any idea I will receive.
    Last edited by martinely95; 09-11-2014 at 03:49 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Searching through multiple excel files

    A VBA solution will require the files to be opened before searching, although can do one at a time to minimize memory utilization.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    Thank you for the quick answer.
    If using VBA requires opening the files, then can you suggest an alternative method/ program? I forgot to say that I am looking for a free solution. I found a couple programs on the Internet but they are all paid versions or they didn't match my requirements. Any suggestions?

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

    Re: Searching through multiple excel files

    Actually you CAN extract the sheet names from a closed workbook. If you Google "Excel VBA Sheet names from closed workbook" you'll find several approaches that will work.

    Once you have mastered getting the sheetnames, you would need to imbed that process in a macro that finds all the files in a given folder, extracts the sheetnames one at a time, does some sort of worksheetfunction calculation on the closed workbook to extract a value using a known working formula, then recording that answer, lather rinse repeat.


    I understand you're looking for free, but all the stuff I outlined above would probably be a few hours of work to getting functioning exactly the way you want. That's a tall order. But someone might jump in to donate that much time.
    _________________
    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!)

  5. #5
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    Thanks for the quick replies!
    @ JBeaucaire
    I lost what were you saying after "extracts the sheetnames one at a time".
    What do you mean with: "does some sort of worksheetfunction calculation on the closed workbook to extract a value using a known working formula"
    I understand that I will need the names of the sheets in the workbook for the search.
    But how do I "tell" the program to search the specific string in a sheet in a closed workbook. What is the code?
    So far I have used Regular expressions for searching in an opened workbook. I just set the regex pattern to have the value of the string I am searching for and loop through the cells which are not empty.

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

    Re: Searching through multiple excel files

    Each of your questions just reveals that you don't know how to do what you're looking to do, and don't even know what you don't know regarding getting it at all. A tall order, as I said.

    "I know my engine is smoking and stuttering and spitting black smoke, but I don't want to pay a mechanic to fix it. How do I fix it myself?"

    See the problem? You're basically saying, "Hey mechanics, show me how to do this for free and then I can claim I fixed it myself... woo hoo!"

    Anyway... Work out the steps/macro for extracting the information from ONE workbook that is open using your given knowledge. Once you have a macro that can do that, you're 60% of the way there. The forum, or Googling, can help you then convert your working macro into one that would:

    1) First work by OPENING the files in a given workbook and extracting the values from each one using your already developed method

    2) The last and biggest hurdle of all, extracting that info without opening the workbooks...

    It's a lot of work, you should really do the groundwork, the ask for help with "steps" along the way.



    Perhaps using a paid product really is the correct approach... or paying someone to do all this work for you.

  7. #7
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    @JBeaucaire
    Thank you for the help.
    I found ADODB. Am I on the right path?
    And one last question. Is searching with the regex pattern the fastest method for searching (for searching in strings with vba in excel)?
    Best regards,
    Martin

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

    Re: Searching through multiple excel files

    REGEX is fast, certainly. But not knowing what you're actually doing makes it hard to comment specifically. If you're NOT going to be opening the workbooks in the end, there's the possibility that your method won't work. However there are many WorksheetFunctions that DO work on closed workbooks, so again, I'd have to know what you're doing to comment specifically.


    One of my clients need me to create a secondary tool for him to use against his master Job Assignments workbook. The problem with his JA was that it was SO huge and so memory intense that opening the wb took five minutes and then any key you pressed, even in other workbooks, caused visual calculation lag.

    The trick I used to access the main sheet's current data without opening the workbook was to create an "image" of that sheet's values in the new workbook using simple "='C:\MyFiles\[99-3z-JobAssignments-v69.xlsx]RoleAssign'!A1" formulas on the image sheet, and this formula was inserted dynamically, meaning he could select any "version" of that workbook and the correct direct links above would be inserted into the IMAGE sheet to recreate the data. The end result is very fast and we were then able to do any calculations we wanted on that data, then repeat again with another workbook.

    So it's possible to run some FORMULAS against a known workbook/worksheet, and it's possible to grab ALL the data from a sheet in a closed workbook without opening from which you can then do just about anything, your REGEX tool would definitely work.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Searching through multiple excel files

    Quote Originally Posted by JBeaucaire View Post
    Actually you CAN extract the sheet names from a closed workbook. If you Google "Excel VBA Sheet names from closed workbook" you'll find several approaches that will work.
    I apologize for misleading the OP! I was not aware of this approach. Plain vanilla VBA must open the file, but as usual, there are more sophisticated ways around the limitation.

  10. #10
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    @ JBeaucaire
    Thank you for the information.
    Here's what I have to do:
    There are a lot of files in a folder. Some are big, some have links in them, some are shared and so on... The thing is that opening them will require a lot of time and resources.
    My goal is to search in these files for a string (a name for example) and have the result:
    -name of the file
    -sheet in the file
    -cell in the sheet (address)
    -cell in the sheet (content)
    It should be good to open the file and select the cell with the result but I will do this later on. Yes, the file(s) with the result will be opened at the end.
    Some time ago I read somewhere that there is a limitation for reading a value from closed workbook (the 255 char in a cell). This will be a huge problem for me if it is true. I do not remember where I have read this or if it really is true? Can you tell me?
    The workbooks have similar content. The strings in which I will be searching for example are on sheet1, column B.
    Later on this program will be changed to search in the whole workbook, not only in one column and sheet.
    And again I'm asking: will my approach with ADODB be successful, reliable and fast?

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

    Re: Searching through multiple excel files

    ADODB speed will be a subjective thing, only you can say how efficient the results "feel".

    Google excel vba use adodb to read excel files and lots of opinions exist, I think you're just going to have to try it.
    http://www.exceltip.com/import-and-e...oft-excel.html

  12. #12
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    @JBeaucaire
    Ok, thanks.
    I am going to try and and I will write later for the results.

  13. #13
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    Here I am again, a lot of hours and a couple of headaches later.
    Here's the file with my achievement:
    Search in folder.xlsm
    I need a little help.
    -My code truncates the strings to the 255 char. This is a big problem. I want to be able to search in the whole string in the cell. I found this: http://support.microsoft.com/kb/189897/en-us
    It didn't helped me a lot. I want to know if I am missing something and there is a way to make the ADO approach working (with strings longer than 255).
    If this is a limit I can't break, then can you offer me another approach for reading values from a closed workbook, which extracts the full string from a cell (as far as I know a cell is limited to 32767 chars so this is the only limit that is satisfactory for me).
    -I don't know what is the code to make my program search in a specific column on a sheet. I know that something should replace the "*" after "Select" but what?
    -I don't know how to extract the cell address from the cell in which the value takes place.

    I think this is all I don't know for now. I am really waiting for replies, because I spent a lot of time creating this. I would be really grateful if somebody tell me at least how to break the 255 character limit.

  14. #14
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Searching through multiple excel files

    I do not think you will obtain cell address using ADO. Also it will not be efficient if you must query all columns for your data. I think opening workbook would be faster. Windows search is perhaps cheapest solution.

    I believe code you have may work if long text is in first rows of workbook.

    Also you do not require LongPtr for your variables - this is only for memory addresses (window handles, pointers and so on).
    Last edited by Izandol; 09-09-2014 at 07:40 PM.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  15. #15
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    Ok. I found a workaround. As @Izandol said in order the code to work a string with length > 255 should be put in EVERY first row in EVERY column. The type of the cells in the column should be text - at least the first 8 -16 rows.
    I have left with one last unanswered question:
    -I don't know what is the code to make my program search in a specific column on a sheet. (I want to search only in column B for example)

  16. #16
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Searching through multiple excel files

    Please Login or Register  to view this content.
    if you do not use headers.

  17. #17
    Registered User
    Join Date
    07-21-2013
    Location
    Smolyan, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Searching through multiple excel files

    I made it. I want to thank everyone for the quick replies and the help. I am changing the thread to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to copy and rename files in vba by searching multiple folders for files
    By razorace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 04:21 AM
  2. Searching Multiple csv files
    By Luke101 in forum Excel General
    Replies: 1
    Last Post: 11-16-2011, 02:08 AM
  3. Cell value searching via multiple files
    By freelance84 in forum Excel General
    Replies: 1
    Last Post: 02-04-2010, 01:35 PM
  4. searching for values through multiple excel files
    By SKooT1027 in forum Excel General
    Replies: 0
    Last Post: 09-15-2008, 11:08 AM
  5. Searching Multiple Files
    By bwg80 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-10-2008, 08:43 PM

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