+ Reply to Thread
Results 1 to 8 of 8

Get list of file names / Document Index

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    80

    Get list of file names / Document Index

    Hello all. I am fairly new to VBA but experienced with Excel.
    We have a folder for each project that contains the documents for that project. Also in this folder is an XLS that lists all the documents in that project folder. A Document Index.

    Currently one person has to manually type the names of the files contained in the project's document folder into this Document Index. I would like to have this task done automatically for her.
    Here is a stripped down version of the Document Index XLS: Document Index.xls

    Note I have a command button in there that says "Get File Names." I'd like for the user to be able to click that button and all the files that are in the folder (that also contains this workbook) are then listed in the appropriate column.
    Some visual aid...
    Before:
    GetFileNames - Before.PNG

    Contents of the folder that the Document Index is in:
    GetFileNames - FolderContents.PNG

    Click the Get File Names button...
    After:
    GetFileNames - After.PNG


    Note I'd need the macro to get the file names of the documents in the folder that this Doc Index is in, and no other folder's contents. Also it would be very nice if the type of the document could be entered in the column to the right of the document name. (See example picture)
    A folder such as this will exist for each of our projects, containing a Document Index, and PDF documents.

    The user who has to fill out the document index has basic knowledge of computers and excel. So going the DOS command prompt isn't an option in this case.


    I've been searching for a couple days now and the closest I got to something was code from this site:
    http://www.vbaexpress.com/kb/getarti...da54213fdf7d82

    It works, but it brings in the entire file path and separates it into columns, I don't need the entire path, just the name of the file. It also pastes the info starting at A1, and overwrites any cells that "get in the way"
    I do not know what ALL the commands in that code mean, I suspect there are extra lines in it that aren't needed for what I'm after.
    However I was able to figure out and read the instructions to change it to only pull fill names of the documents in the folder that the workbook is in. (partial win ) This code is in the XLS I attached. If I need to delete it and start from scratch please let me know.

    One of the abilities I need is to be able to change where the file names get inserted.


    Please be patient with my lack of experience in VB and with it being the weekend. I will check back on the thread as often as I can.
    Any help in this matter will be greatly appreciated. Thank you.
    Last edited by Fett2oo5; 03-04-2013 at 01:47 PM. Reason: Marking as solved. hafizimran provided exactly what I needed.

  2. #2
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Document Index. Get→Insert a list of file names

    Please Login or Register  to view this content.
    Last edited by hafizimran; 02-23-2013 at 03:53 PM.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Document Index. Get→Insert a list of file names

    Ok

    This file is a stripped down version of a file that I created for my son.

    It originally found all text files in a folder and its subfolders and changed the headers, footers, and watermarks and then saved the files in the latest version of MS word.

    So it is probabally overkill for what you need.

    All you need to do is save the macro in the folder that you are interested.

    Open the file and click on the button.

    if it works for you then you can speeed up the process by:

    1. rename the macro as auto_open() it will then run automatically as soon as the worksheet is opened.
    2. use excel options to declare the folder where the macro is as a safe location.
    This will stop excel asking for permission to run the macro.

    to this this click on the ms logo at the top left ox excel.
    select trust centre
    then trust centre settings
    then trusted locations
    then add new location
    then browse to find and select your folder.

    Enjoy
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-17-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Document Index. Get→Insert a list of file names

    Wow! Thank you hafizimran, this is exactly what I was looking for! It solves the problem I am facing and your comments are helpful. You even made it possible for me to change the location of where the data is inserted. AND, you did it in just 15 mins! I'm impressed!
    Thank you very much.

  5. #5
    Registered User
    Join Date
    12-17-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Document Index. Get→Insert a list of file names

    Quote Originally Posted by hafizimran View Post
    Please Login or Register  to view this content.
    hafizimran - Is there a way to omit the extension from being entered? I tried deleting it, also tried commenting it out, both resulted in excel hanging up and ultimately had to be closed via task manager. Any help?

  6. #6
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Get list of file names / Document Index



    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-17-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Get list of file names / Document Index

    How about just the file name with no extension?
    I have an application for both. There are two different kinds of lists. While one list requires the extension in the next cell, the other list does not, it only needs to display the file name.

    Thank you for all the help.

  8. #8
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Get list of file names / Document Index

    Please Login or Register  to view this content.

+ 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