Results 1 to 1 of 1

processing data in subfolders 2-3 levels deep

Threaded View

  1. #1
    Registered User
    Join Date
    12-13-2015
    Location
    Canada
    MS-Off Ver
    Office XP
    Posts
    1

    Post processing data in subfolders 2-3 levels deep

    Hello All

    I am new to VB script and would like help in processing data 2 to 3 level deep.

    I currently am running a script that will read specific lines from an excel files that is stored within main folder one level deep. How do i modify the existing code to read excel data from files stored 2 or sometimes 3 level deep in sub folders . can you help me with modifying this script.


     
    Sub Consolidated_Trail1()
    'Processes all subfolders in a main folder, one level deep
    
    Dim FSO As Object, FLD As Object, SubFLDRS As Object, SubFLD As Object, f As Object
    Dim fNAME As String, fPATH As String, NextRw As Long
    Dim wsMain As Worksheet, wbData, WsSrc, WckSrc As Workbook
    
    'Set f = FSO.GetFolder("C:\Documents and Settings\xxxx\Desktop\xxx")
    
    fPATH = "N:\PxxxxxI\"     'don't forget the final \ in this string
    
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FLD = FSO.GetFolder(fPATH)
    Set SubFLDRS = FLD.SubFolders
    Set wsMain = ThisWorkbook.ActiveSheet
    
    Application.ScreenUpdating = False
    
    wsMain.UsedRange.Offset(1).EntireRow.ClearContents
    NextRw = 2
    
    
    wsMain.Range("A1:P1").Value = Array("Project Desc.", "Component", "Project No.", "MPI No.", "99", "A", "L", "B", "C", "D", "F", "G", "Total", "Status", "Filename", "Dwg No.")
    
    
    For Each SubFLD In SubFLDRS
       
        fNAME = Dir(fPATH & SubFLD.Name & "\" & "*.xls")
          
        Do While Len(fNAME) > 0
        
            Set wbData = Workbooks.Open(fPATH & SubFLD.Name & "\" & fNAME)
           
                 Set WsSrc = wbData.ActiveSheet
     
            wsMain.Range("A" & NextRw).Value = WsSrc.Range("A11")
            wsMain.Range("B" & NextRw).Value = WsSrc.Range("F11")
            wsMain.Range("C" & NextRw).Value = WsSrc.Range("L11")
            wsMain.Range("D" & NextRw).Value = WsSrc.Range("J11")
            wsMain.Range("E" & NextRw).Value = WsSrc.Range("Q14")
            wsMain.Range("F" & NextRw).Value = WsSrc.Range("Q15")
            wsMain.Range("G" & NextRw).Value = WsSrc.Range("Q20")
            wsMain.Range("H" & NextRw).Value = WsSrc.Range("Q16")
            wsMain.Range("I" & NextRw).Value = WsSrc.Range("Q17")
            wsMain.Range("J" & NextRw).Value = WsSrc.Range("Q21")
            wsMain.Range("K" & NextRw).Value = WsSrc.Range("Q19")
            wsMain.Range("L" & NextRw).Value = WsSrc.Range("Q18")
            wsMain.Range("M" & NextRw).Value = WsSrc.Range("Q22")
            wsMain.Range("N" & NextRw).Value = WsSrc.Range("R14")
            wsMain.Range("O" & NextRw).Value = fNAME
            wsMain.Range("P" & NextRw).Value = WsSrc.Range("A7")
                  
            wbData.Close False
            NextRw = NextRw + 1
            fNAME = Dir
        Loop
       
    Next SubFLD
    
    End Sub
    
    
    
    
    
    Private Sub CommandButton1_Click()
    Consolidated_Trail1
    End Sub

    Moderator Note:


    Welcome to the forum. Pls be sure that you use code tags around your codes when you post.
    .
    Last edited by Fotis1991; 12-15-2015 at 03:45 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. Create folders in all the subfolders and move subfolders
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 12:51 PM
  3. Sheet-related processing causes Excel VBA Userform to stop processing Tab/Enter
    By Joaquin M Lopez Muno in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-22-2014, 03:02 PM
  4. Reduce processing time for processing multiple excel sheets
    By rexer231 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 09:25 AM
  5. Replies: 3
    Last Post: 07-06-2012, 08:40 PM
  6. Macro to Loop within all subfolders in a folder in three levels
    By sarakhalatbari in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2011, 06:20 AM
  7. custom menu 4+ levels deep
    By blayne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2006, 04:30 PM

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