+ Reply to Thread
Results 1 to 12 of 12

Search File (String) name and Path

  1. #1
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Search File (String) name and Path

    HI All,

    I am looking for a VBA Excel code to look at the file name (column a) and return the full path (column b).
    The File name may be in any of the sub folders and the code should return the exact file name and path to show where it is located.

    Example

    Column A : Test1
    Column b: C:\Temp\Documents\Test1

    Column A: Test99
    Column B: C:\Temp\Documents\Test99


    Appreciate your help on this.

    Reference : have followed the steps within this documentation https://help.salesforce.com/articleV...e=en_US&type=1

    Thank you,
    Masond3
    Last edited by masond3; 09-14-2017 at 01:11 PM. Reason: Adding additional Ref Material

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    are you wanting:
    - some VBA to search through all the sub-folders of C:\Temp\Documents\ and create a 2 column worksheet
    OR:
    -some VBA to look-up the values in column A and return the path in column B by searching through sub-folders

    Is there only one level of sub-folder or are there sub-sub folders?
    Last edited by kev_; 09-14-2017 at 01:00 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Re: Search File (String) name and Path

    Hi Kev,

    There could be sub-sub folders. But for testing purposes its only one level deep.
    And Some VBA to look at column A and return path in Column B by searching folders and sub/sub-sub folders

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    Ok - will post some code tommorow morning

  5. #5
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Re: Search File (String) name and Path

    Hi Kev,

    Thank you very much.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    I have elected to dump all values to the workbook
    - makes it much easier to test and see what is going on

    This should get you very close:
    - Open the attached file
    - Add some values to search for into column A in sheet "Results"
    - run macro ListMyFiles with {CTRL} L
    (creates entries in sheets F1 and F2)
    - run macro EnterPath with {CTRL} K
    (puts found paths in columnB in sheet "Results"

    The default is that column A is assumed to not include the file extension and that is what is searched for
    - the first matched file is returned - so this may give wrong result if a PDF and Excel file contain the same name
    - the code is flexible and we can fix that easily
    - the workbook VBA includes an example of how to restrict search to xlsx extensions (will explain thsi later if necessary)

    Sublayers: - also for later - but flexibility is in-built
    set to 0 excludes sub-folders
    1 = 1 level, 2 = 2 levels

    Any problems, please do not struggle, just let me know

    All code is in same module:
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by kev_; 09-15-2017 at 08:13 AM.

  7. #7
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Re: Search File (String) name and Path

    HI Kev,

    Thanks for providing a working solution.

    When I was doing my analysis I noticed that there was duplicate File Names.
    What i will do is appen an Id infront of the FileName which will make the name distinct.

    I am going through the steps you provided but i am encountering one issue.

    On the Results tab column B "Not Found". However when i look at tabs F1/F2 the data is populated

    This is the current structure

    Pathway : C:\Temp\Documents
    Filename : 00P0V00000oS28HUAS

    Tab F1: – Returns “C:\Temp\Documents”
    Tab F2: returns “00P0V00000oS28HUAS 00P0V00000oS28HUAS C:\Temp\Documents\00P0V00000oS28HUAS
    Last edited by masond3; 09-15-2017 at 09:37 AM. Reason: Re-Ordering Msg

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    duplicate File Names:
    What i will do is appen an Id infront of the FileName which will make the name distinct
    - sensible approach (if small in number)
    Why the duplicate?
    - do they have different extensions?


    Tab F1: – Returns “C:\Temp\Documents”
    Tab F2: returns “00P0V00000oS28HUAS 00P0V00000oS28HUAS C:\Temp\Documents\00P0V00000oS28HUAS

    You have thrown a curveball here!

    Please check the file's name on your system - looks like it may be missing its extension perhaps
    - is there anything in column B on sheet F2?

    Modification
    I will send you a modification to the code to notify user if a file does not have an extension
    - the correct approach here is to fix the file name rather than allow for it in the code -do you agree?
    Last edited by kev_; 09-15-2017 at 10:05 AM.

  9. #9
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Re: Search File (String) name and Path

    Hi Kev,
    Loving the logos
    I think it is the file name is missing as tried it on other files and seems to be working correctly. May of sent the email a tad too soon..

    So we have a DB which holds attachments. In the attachment DB we have a couple of columns Id, parentid, name etc ...

    Id = Unique attachment Id
    Parentid : Record the attachment is attached to
    name : Name of attachment

    So we may have a 1 pdf called (Mason) which is attached to 5 records. In our DB that would come through 5times. Thats why why ID is important as its unique

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    Are you asking me a question?

    So we have a DB which holds attachments.
    In the attachment DB we have a couple of columns Id, parentid, name etc ...
    Id = Unique attachment Id
    Parentid : Record the attachment is attached to
    name : Name of attachment
    What is the DB?
    - another Excel file, another worksheet, an (Access?) database


    So to help you I need to know where this data is held, how it is linked to its parent(=name) etc and how we get things right in the file listings

    Am i missing something
    - my browser cannot open that link you included in post#1 so I may be "flying blind"

  11. #11
    Forum Contributor
    Join Date
    11-11-2011
    Location
    London, England
    MS-Off Ver
    EXCEL 2013
    Posts
    324

    Re: Search File (String) name and Path

    Hi Kev,

    So our DB (Database) is Salesforce. I will have to extract the data from Salesforce and store on a Drive somewhere.
    This article here -https://help.salesforce.com/articleView?id=000007269&language=en_US&type=1 explains the technique to use to rename export Attachments.

    The exercise i need is to get the right Pathway associated to correct attachment.

    Using the technique to rename exports (I may have to make some small tweaks) i should have a one to one mapping

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Search File (String) name and Path

    not sure if I can help you with Pathway DB etc
    - but if you can get the values into a workbook so that I can set up a lookup table..... etc

    So we may have a 1 pdf called (Mason) which is attached to 5 records. In our DB that would come through 5times. Thats why why ID is important as its unique
    Just thinking aloud (sorry if I am rambling, but I cannot see your data...)

    - in column A in your original file (ie what comes off your system) does Mason appear 5 times?
    - if so, can you tell the 5 Masons apart when looking in your original file?
    - if you cannot, could VBA perhaps amend the name in columnA as it grabs the filepath for each of the 5 entries (I am hoping the 5 files are listed on F2)

    - in folder C:\Temp\Documents (or sub-folders) does Mason appear with 5 different extensions or 5 different names?
    - if so that would suggest that the file listings in sheet F2 contain the name Mason 5 times - how do they differ?

    Where my mind is heading...
    - can we get a handle on the different Masons in your original file in a way that we can tie them up to the listed files on F2?
    - or if the files are listed 5 times in F2 listings can we work backwards from there and marry everything up somehow
    Last edited by kev_; 09-15-2017 at 11:05 AM.

+ 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. Dir file search, set file path from cell content
    By beenbee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2015, 01:13 PM
  2. [SOLVED] Search a string and return the full file name and path
    By akhileshgs in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-27-2014, 04:54 AM
  3. Replies: 0
    Last Post: 05-08-2014, 11:42 AM
  4. [SOLVED] how to insert file path of every file in a folder as a string?
    By Gamekiller48 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-31-2013, 02:01 PM
  5. VBA Excel function to search computer for given file name and return file path
    By knuckles2290 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2013, 02:35 AM
  6. Replies: 1
    Last Post: 08-04-2009, 06:42 AM
  7. Use String Variables in File Path and create path if not existing
    By JanBang in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2007, 09:04 AM

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