+ Reply to Thread
Results 1 to 2 of 2

VBA code required to count the number of files in multipe directories.

  1. #1
    Registered User
    Join Date
    MS-Off Ver
    Excel 2007

    VBA code required to count the number of files in multipe directories.

    I've made a code to get the path of the files in a particular directory. But, I would want the path of the files from other folders as well. Can someone please help me on what changes are required in order to get the path of the file from multiple directory. Thank you for your help in advance. Below is the VBA code:

    Sub LoopThroughFolder()
    Dim r As Integer 'Row as unique
    r = 2 'Row 2
    Sheets("sheet1").Select 'Selects the sheet 1
    Range("A2:E5000").ClearContents 'Clears the contents on every run
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject") 'File System object created
    Set FolderObj = FileSystemObject.getfolder("C:\Users\Yash") 'Directory
    For Each FileObj In FolderObj.Files 'loop through files
    If Not FileObj.Attributes And 2 Then 'Only show files that are not hidden
    Cells(r, 1).Value = FileObj.Path 'Output
    r = r + 1 'Next value = next cell
    End If 'If it's hidden files it will not be considered in the output
    Next FileObj 'All the files are selected
    End Sub
    Last edited by yaash; 05-26-2013 at 08:54 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    Hamburg, Germany
    MS-Off Ver
    2013 on Win10 (desktop), 2007 on Win10 (notebook)

    Re: VBA Help required.


    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    And when doing so please add code-tags around your procedure for better readability.

    You would need to work a little bit on this code:
    Please Login or Register  to view this content.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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


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