There's a program I'm trying to modify (VB 6) that contains a section of code that looks for an Excel file (according to a file name snippet in another program). At this point it will only go out and look for one file and add that total to a report, but I would like it to go out and look for more than one file (the file name snippets would be separated by a semicolon) and get the totals for all the Excel files and add them together.
Here is the code section is question. Any help is appreciated. I haven't had ANY luck.
''GET EXCEL FEASIBILITY STUDY DATA
FileNameStart = MDIParent.Adodc1.Recordset.Fields("USER_4")
If FileNameStart = "" Or IsNull(FileNameStart)
Then GoTo AddRec
EST_MAT_COST = 0
EST_LAB_COST = 0
FileName = ""
''CHECK FILE NAME
For I = 0 To File1.ListCount - 1
File1.ListIndex = I
If UCase(Left(File1.FileName, Len(FileNameStart))) = UCase(FileNameStart)
Then FileName = File1.FileName
Exit For
End If
Next I
If FileName <> ""
Then xlFile.Workbooks.Open ExcelPath & "\" & FileName
Dim xlSheet As Excel.Worksheet
Set xlSheet = xlFile.Sheets("NRE")
''SEARCH FOR ''TOTAL''
CONTINUE = True
ROW_COUNT = 1
Do While CONTINUE
If xlSheet.Cells(ROW_COUNT, 1) = "TOTAL" Then
Exit Do
End If
ROW_COUNT = ROW_COUNT + 1
Loop
EST_MAT_COST = xlSheet.Cells(ROW_COUNT, 5) + xlSheet.Cells(ROW_COUNT, 6) + xlSheet.Cells(ROW_COUNT, 7)
EST_LAB_COST = xlSheet.Cells(ROW_COUNT, 4)
xlFile.ActiveWorkbook.Close False
xlFile.Quit
End If
Here is the code section is question. Any help is appreciated. I haven't had ANY luck.
''GET EXCEL FEASIBILITY STUDY DATA
FileNameStart = MDIParent.Adodc1.Recordset.Fields("USER_4")
If FileNameStart = "" Or IsNull(FileNameStart)
Then GoTo AddRec
EST_MAT_COST = 0
EST_LAB_COST = 0
FileName = ""
''CHECK FILE NAME
For I = 0 To File1.ListCount - 1
File1.ListIndex = I
If UCase(Left(File1.FileName, Len(FileNameStart))) = UCase(FileNameStart)
Then FileName = File1.FileName
Exit For
End If
Next I
If FileName <> ""
Then xlFile.Workbooks.Open ExcelPath & "\" & FileName
Dim xlSheet As Excel.Worksheet
Set xlSheet = xlFile.Sheets("NRE")
''SEARCH FOR ''TOTAL''
CONTINUE = True
ROW_COUNT = 1
Do While CONTINUE
If xlSheet.Cells(ROW_COUNT, 1) = "TOTAL" Then
Exit Do
End If
ROW_COUNT = ROW_COUNT + 1
Loop
EST_MAT_COST = xlSheet.Cells(ROW_COUNT, 5) + xlSheet.Cells(ROW_COUNT, 6) + xlSheet.Cells(ROW_COUNT, 7)
EST_LAB_COST = xlSheet.Cells(ROW_COUNT, 4)
xlFile.ActiveWorkbook.Close False
xlFile.Quit
End If