code that retrieves all values in a folder

Asked 2 years ago, Updated 2 years ago, 357 views

How do I get all the values in the folder?
The macro below will only get the first value of the book.
I'd like to transfer all the values I got, so please tell me how to do it.

Sub-Single Test Specification Macro()
DimwFile As String
DimwFilePath As String
Dimi As Long
 
US>'Return file name if Excel file exists
wFile=Dir (ActiveWorkbook.Path&"\*.xlsx")
 
'Specify first line
i = 2
 
US>'Read all Excel files in the current directory
Do While wFile <>"
     
    'Get the full path of the Excel file to open
    wFilePath=ActiveWorkbook.Path&"\"&wFile
     
    'Function (program) name, number of tests, completion, and number of defects are acquired and stored in an array (separator character: |)
    strData=Split(File_Load(wFilePath), "|")
     
    US>'Function (program) name
    Cells(i,1) = strData(0)
     
    'Test Case
    Cells(i,2) = strData(1)
     
    US>'Completed Count
    Cells(i,3) = strData(2)
    
    'Number of defects
    
    Cells(i,4) = strData(3)
      
     
    'Get the following Excel file
    wFile=Dir()
     
    'Count the number of rows
    i=i+1
 
Loop
 
    MsgBox "Completed"
End Sub

Function File_Load (ByVal wFilePath As String) As String

    Dimwb As Workbook
    DimwItem As Variant
    Dimi As Long
    Dim FoundCell As Object

    Set wb=Workbooks.Open(wFilePath)

    wItem=Array("Feature (program) name", "Test Count", "Completed Count", "Defect Count")

    Fori= LBound(wItem) To UBound(wItem)

        Set FoundCell=wb.Works(1).Cells.Find (What:=wItem(i))

        If FoundCell Is Nothing Then
            wItem(i)=""
        Else
            wItem(i) = FoundCell.Offset(10).Value
        End If

    Next i

    wb.Close SaveChanges: = False

    File_Load=Join(wItem, "|")


End Function

vba

2022-09-30 22:01

1 Answers

Could you please try the steps?
Apparently, the dir function part is correct, so we can only consider if the while statement part passes only once (it escapes without a loop).

while <>"

wend

It should work even if you write down the loop in , so if you don't know how to write down the downhill, why don't you rewrite it?

Also, the first part of the dir() is the xlsx file, but if the target is an xls cut extension, it is assumed that it will not respond.
In that case, if you write "*.xls?", you can get all xlsx, xlsm, and xls, but if you have a file with VB in the same hierarchy, it will be included, so you may need to take exception action.


2022-09-30 22:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.