+ Reply to Thread
Results 1 to 21 of 21

Finding a file in sub folders and taking you to the location of searched file

  1. #1
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Finding a file in sub folders and taking you to the location of searched file

    • I have a couple of drawings in PDFs and .dwg file format .
    • All files are stored in sub folders which are in turn saved in a folder; which sits in C:



    I am trying to write a VBA program that requests you to enter the file name and then looks for it in each sub folder in the main folder.
    When found, directly open up the location of the file., i.e , take me directly to where the file is .

    I there a way to do it ?

    Use the following code :
    It just reports where the file is available. But does not open the location of the file .

    Please Login or Register  to view this content.
    Source for above code :
    http://social.msdn.microsoft.com/For...subdirectories
    Last edited by subbby; 10-04-2013 at 01:22 PM. Reason: SOLVED

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    how about this:
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Hello,

    Thanks for your code.

    Although the code had no errors, it always returned saying " NO FILE FOUND" . I did change the path in 'finfolderin' in the code.

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    Hi,

    please take care to enter the filename with the extension, e.g. "ss.txt"

    "ss" will not be found.

  5. #5
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    That worked... Thanks.

    is there a way to do for any a file whose extension is unknown ? The only three possibilities are
    .dwg, .dwf and .pdf
    . the given file name could be with any extension

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    Hi,

    so you want to enter the file-name without extension, and only the following extensions will be taken into consideration: "dwg", "dwf", "pdf"
    In case of a finding the folder will be opened and the file selected. The next step would be to implement the selection of the folder to start searching, or is it always the same?
    Try: Book1.xlsm

    code:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Quote Originally Posted by tehneXus View Post
    Hi,


    In case of a finding the folder will be opened and the file selected. The next step would be to implement the selection of the folder to start searching, or is it always the same?
    Try: Attachment 268798
    I am not sure I followed what you said here. However, here is what I am trying to do.
    1. enter the file name (without extension)
    2. NEED NOT display the path. instead, just take me directly to that folder
    3. copy the file from this folder onto another folder (Folder path- C:/Documents)
    4. OPTIONAL : copy the file name onto a cell in an excel sheet


    I would be glad if you could help me until # 3.

  8. #8
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    Quote Originally Posted by subbby View Post
    1. ...
    2. ...
    3. copy the file from this folder onto another folder (Folder path- C:/Documents)
    4. OPTIONAL : copy the file name onto a cell in an excel sheet
    If you want to copy the file automatically and write the name (source and target folder too?) into the sheet, do you still want to open the explorer window?




    This will not show the path in msgbox, still open the explorer, copy the file, write to sheet
    Please change the target folder to be copied to in
    Please Login or Register  to view this content.
    # Book1.xlsm #

  9. #9
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Quote Originally Posted by tehneXus View Post
    If you want to copy the file automatically and write the name (source and target folder too?) into the sheet, do you still want to open the explorer window?

    It need not open the explorer window .

    in the The excel workbook you attached , is "M_STR_TARGET_PATH " the target folder and "FindFileInFolder" the folder in which it searches for the user given file name ?

    I tried to run with my paths. It gave me permission denied and highlighting the following :

    Please Login or Register  to view this content.
    Last edited by subbby; 10-04-2013 at 08:54 AM.

  10. #10
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Capture1.jpgCapture2.jpgCapture3.jpg

    These are the errors I encountered .

  11. #11
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    There is a backslash missing at the end of "M_STR_TARGET_PATH", which is the target folder

    If this will not solve your problem try this:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    i put the back slash and it worked... Did what I wanted it to do.

    Thank you very much !

  13. #13
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Is there a way I could use a different extension instead of .dwf ?
    Its and .idw file !

  14. #14
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    The following line lists the extensions to look for, just add/remove whatever you want:
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Quote Originally Posted by tehneXus View Post
    The following line lists the extensions to look for, just add/remove whatever you want:
    Please Login or Register  to view this content.
    The first thing I did was trying that . It said "FILE NOT FOUND"

    let me try again.
    Last edited by subbby; 10-04-2013 at 03:07 PM.

  16. #16
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    To ignore the case of the extension use:
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Capture4.jpg

    Pls see attached . this was the error.

  18. #18
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    Please Login or Register  to view this content.
    should not be commented ^^

    USE:
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Hello,

    I have been trying this and works successful except on files with .idw extension . I have to completely type in the full file name with the .idw extension for the code to locate it.

    Also, is there a way to fasten the search process? This program is for searching a drawing database that has data since 1835.

    Thanks for your help.

    Appreciate it !

    The following is the code I have now :

    Please Login or Register  to view this content.

  20. #20
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding a file in sub folders and taking you to the location of searched file

    please check if this runs faster and finds "*.idw" files.
    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Finding a file in sub folders and taking you to the location of searched file

    Hello,

    Thanks for getting back. With this new code, any file I search, it just gives "FILE NOT FOUND" box. Pls find the snapshot attached herewith this reply post.


    • I have the FIND FILE IN as C:\Copies. (for it to search in this and all sub folders)
    • I searched for a100a23 but it said file not found
    • Am I missing something ?
    • In the input box I gave – a100a23 …. (no extensions)
    Capture5.jpg

+ 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. VBA code to open folders and pdf file inside the folders
    By kirtesh250187 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2013, 03:17 AM
  2. Save as macro that specifies file type, file location and takes file name from three cells
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-13-2013, 10:09 PM
  3. Replies: 0
    Last Post: 04-15-2013, 06:54 AM
  4. VBA code for searching file through folders and sub folders
    By vikas189 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2012, 06:00 PM
  5. Replies: 1
    Last Post: 10-01-2012, 11:46 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