Code for looping through all excel files in a specified folder, and pulling data from specific cells

后端 未结 5 1910
南笙
南笙 2020-11-27 07:53

I have about 50 or so Excel workbooks that I need to pull data from. I need to take data from specific cells, specific worksheets and compile into one dataset (preferably in

5条回答
  •  一生所求
    2020-11-27 08:27

    It could be done with the following code

    Sub LoopThroughFiles()
    
    Dim StrFile As String
    StrFile = Dir("V:\XX\XXX\*.xlsx")
     Do While Len(StrFile) > 0
        Debug.Print StrFile
           Set wbResults = Workbooks.Open("V:\XX\XXX\" & StrFile)   
    
                        'DO YOUR CODE HERE
    
    
           wbResults.Close SaveChanges:=True
        StrFile = Dir
     Loop
    End Sub
    

提交回复
热议问题