• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to loop till folder ,subfolder and subfolder down till end

trprasad78

Member
I have code which work fine till subfolder, but it not working subfolder under folders.

i got the link from chandoo.org forum
http://www.cpearson.com/excel/recursionandfso.htm

but i dont know where to modify , please help me to modify the below code.

Code:
Sub RunMacroInSubfolders()

    Dim objFSO As Object
    Dim objFolder As Object
    Dim objSubFolder As Object
    Dim objFile As Object
    Dim MyFolder As String
    Dim wkbOpen As Workbook
    Dim wkb As Workbook
    Dim wks As Worksheet
    Dim CalcMode As Long

    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
    End With
   
    'Change the path accordingly
    MyFolder = "F:\Dec'16"
   
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(MyFolder)
    Set wkb = ActiveWorkbook
    Set wks = ActiveSheet
   
    For Each objSubFolder In objFolder.SubFolders
        For Each objFile In objSubFolder.Files
            Set wkbOpen = Workbooks.Open(objFile.path)
            'Your code here
            Call Create_ExportSheet
           
           
            wkbOpen.Close SaveChanges:=True
        Next objFile
    Next objSubFolder
   
    With Application
        .Calculation = CalcMode
        .ScreenUpdating = True
        .EnableEvents = True
    End With

    MsgBox "Completed...", vbInformation
   
End Sub
 
Hello Mr prasad.

Your code works perfectly...Till subfolders...check the xlsx file which you have stored under subfolders where you are calling "Call Create_ExportSheet"...still have any problem..

give us more information to complete your task...Happy to help you.
 
Thank you @Hui sure i will check. that.
@Monty That code working if the file is available in all folder.
Example

FOLDER DEC> RAM> 2 excel files
FOLDER DEC> VICTOR>5 EXCEL FILES
Folder DEC>PETER> NO EXCEL FILE > under peter folder JIM Folder>5 excel file.

In above scenario macro work only till next subfolder. if the subfolder is empty it got exit the macro.

so i want that macro as to run all folder if its empty it hast to skip and check next folders or subfolder avilable.

Thank you :)
 
Hello Prasad.

I have checked the code by created 5 to 6 folders with some excel files and one empty folder...and code is working perfectly fine...if you still think some thing wrong...please provide me the code for (Call Create_ExportSheet)...just wanted to check what exactly you are doing..

Happy to help..
 
Hello Prasad.

I have checked the code by created 5 to 6 folders with some excel files and one empty folder...and code is working perfectly fine...if you still think some thing wrong...please provide me the code for (Call Create_ExportSheet)...just wanted to check what exactly you are doing..

Happy to help..
Thank you :)
i got another code which working in all the folder.
 
Back
Top