There's a couple of things to note with the code you just posted:
(1) If only 1 file is selected, element 0 contains the full path and file
(2) There's no need to trap an error if the user doesn't select a file. The UBound is set to -1 in that case.
I have adjusted your code (and mine in Post #13) and integrated them. There are now two CommandButtons, one to Create the list of files (cmdGetFileNames) which will populate the ListBox and the other (cmdCreateOutput) which will perform the processing on each file in the LstBox (it removes the file from the ListBox when it's been processed)
Note that it will add whatever is in Text2.Text (or 0.5) to the EC1 value for every file.Code:Private Sub cmdCreateOutput_Click() Dim strFileToProcess As String With List1 If .ListCount > 0 Then For intI = .ListCount - 1 To 0 Step -1 strFileToProcess = Mid$(Label1.Caption, InStr(Label1.Caption, ": ") + 2) & .List(intI) Call ProcessFile(strFileToProcess) .RemoveItem intI Next intI .AddItem "Files have been Processed" End If End With End Sub Private Sub cmdGetFileNames_Click() Dim strFileNames() As String Dim i As Integer Dim intI As Integer strFileNames = Split(GetFiles, Chr(0)) With List1 If UBound(strFileNames) <> -1 Then .Clear If UBound(strFileNames) = 0 Then Label1.Caption = "Files selected from: " & Mid$(strFileNames(0), 1, InStrRev(strFileNames(0), "\")) strFileNames(0) = Mid$(strFileNames(0), InStrRev(strFileNames(0), "\") + 1) .AddItem strFileNames(0) Else 'If more than one file is selected the Path is stored in index 0 of array files in index 1... If Mid$(strFileNames(0), Len(strFileNames(0))) <> "\" Then strFileNames(0) = strFileNames(0) & "\" Label1.Caption = "Files selected from: " & strFileNames(0) For i = 1 To UBound(strFileNames) .AddItem strFileNames(i) Next End If Else Label1.Caption = "No Files Selected" End If End With End Sub Private Sub ProcessFile(strFile As String) Dim intFileIn As Integer Dim intFileOut As Integer Dim intI As Integer Dim intPos As Integer Dim strData As String Dim dblVal As Double Dim strOFile As String Dim strRecords() As String Dim strFields() As String ' ' Allocate a File Number, open, read the entire contents and close the file ' intFileIn = FreeFile Open strFile For Input As intFileIn strData = Input(LOF(intFileIn), intFileIn) Close intFileIn ' ' Create a name for the output file ' intPos = InStrRev(strFile, ".") If intPos > 0 Then strOFile = Mid$(strFile, 1, intPos - 1) & "_OUT" & Mid$(strFile, intPos) Else strOFile = strFile & "_OUT" End If ' ' Open the output file ' intFileOut = FreeFile Open strOFile For Output As intFileOut ' ' Split the input data into records ' strRecords = Split(strData, vbNewLine) ' ' Process each non-null record ' If it's a record type of EC1 then split it into fields ' add whatever is in text2.text to the 3rd field ' replace the original value with the new value ' For intI = 0 To UBound(strRecords) If strRecords(intI) <> "" Then intPos = InStr(strRecords(intI), "EC1") If intPos > 0 Then strFields = Split(strRecords(intI), " ") If UBound(strFields) > 2 Then dblVal = CDbl(strFields(3)) If IsNumeric(Text2.Text) Then dblVal = dblVal + CDbl(Text2.Text) Else dblVal = dblVal + 0.5 End If strFields(3) = Format(dblVal, "#0.##0") strRecords(intI) = Join(strFields, " ") End If End If ' ' Write the record to the output filer ' Print #intFileOut, strRecords(intI) End If Next intI Close intFileOut End Sub Public Function GetFiles(Optional ByVal sTitle As String = "Open files...") As String ' sTitle: Optional Title of Dialog Dim sFilenames As String ' Get the desired name using the common dialog Set cdlOpen = CreateObject("MSComDlg.CommonDialog") ' set up the file open dialog file types With cdlOpen .CancelError = False .Filter = "Raw Files (*.raw)|*.raw|All Files (*.*)|*.*" .FilterIndex = 1 .DialogTitle = sTitle ' set up Common Dialog flags ' same as .Flags = cdlOFNHideReadOnly Or cdlOFNPathMustExist Or cdlOFNLongNames Or cdlOFNAllowMultiselect or cdlOFNExplorer .Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000 .ShowOpen ' get the selected name sFilenames = .FileName End With GetFiles = sFilenames Set cdlOpen = Nothing End Function




