Results 1 to 2 of 2

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

Threaded View

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    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.

Thread Information

Users Browsing this Thread

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

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