I'm trying to use Excel file to open multiple text files ( all files are in the same directory ) and parse for specific key words. I'm trying to list the name of files to be processed in worksheet Files cells E10 to end of files listed below.
I'm trying to parse these files for specific keywords like XX-0039 and then paste the information from that line into different cells of withing worksheet Data. Unfortunately I cannot get this script to open more that 1 file ie. Files listed in cells E11,E12..etc...
Can someone please help me...
Public Sub GetData()
Dim NumRows As Integer
Dim x As Integer
Dim y As String
Dim strDirectory As String
Dim strFile As String
Dim lngS As Long 'row count variable in data worksheet for processing events
Dim data As String 'data variable for reading text files
Dim test As String
Dim error_code As String
lngS = 2
lngCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
DoEvents
strDirectory = ActiveWorkbook.Path & "\"
'Clear out the old
Sheets("Data").Activate
Range("A6:c65000").ClearContents
k = 2
lngS = k + 4
Worksheets("Files").Activate
NumRows = Range("E65536").End(xlUp).row
For x = 10 To NumRows
strFile = Cells(x, 5).Value
strFile = strDirectory + strFile
'Filter the tool text file
Open strFile For Input As #1
Do While Not EOF(1)
Line Input #1, data
test = Mid(data, 14, 7)
If Mid(data, 14, 7) = "XX-0039" Or Mid(data, 14, 7) = "33-0052" Or Mid(data, 14, 7) = "XY-5953" Then
Sheets("Data").Activate
a = Replace(data, vbTab, "")
error_code = Trim(Mid(a, 14, 7))
event_name = Trim(Mid(a, 12, 999))
eventtime = Trim(Mid(a, 23, 28))
Range(CStr("a" & lngS)).Value = event_name
Range(CStr("b" & lngS)).Value = eventtime
Range(CStr("c" & lngS)).Value = error_code
lngS = lngS + 1
End If
DoEvents
Loop
Close #1
Next
End Sub
I'm trying to parse these files for specific keywords like XX-0039 and then paste the information from that line into different cells of withing worksheet Data. Unfortunately I cannot get this script to open more that 1 file ie. Files listed in cells E11,E12..etc...
Can someone please help me...
Public Sub GetData()
Dim NumRows As Integer
Dim x As Integer
Dim y As String
Dim strDirectory As String
Dim strFile As String
Dim lngS As Long 'row count variable in data worksheet for processing events
Dim data As String 'data variable for reading text files
Dim test As String
Dim error_code As String
lngS = 2
lngCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
DoEvents
strDirectory = ActiveWorkbook.Path & "\"
'Clear out the old
Sheets("Data").Activate
Range("A6:c65000").ClearContents
k = 2
lngS = k + 4
Worksheets("Files").Activate
NumRows = Range("E65536").End(xlUp).row
For x = 10 To NumRows
strFile = Cells(x, 5).Value
strFile = strDirectory + strFile
'Filter the tool text file
Open strFile For Input As #1
Do While Not EOF(1)
Line Input #1, data
test = Mid(data, 14, 7)
If Mid(data, 14, 7) = "XX-0039" Or Mid(data, 14, 7) = "33-0052" Or Mid(data, 14, 7) = "XY-5953" Then
Sheets("Data").Activate
a = Replace(data, vbTab, "")
error_code = Trim(Mid(a, 14, 7))
event_name = Trim(Mid(a, 12, 999))
eventtime = Trim(Mid(a, 23, 28))
Range(CStr("a" & lngS)).Value = event_name
Range(CStr("b" & lngS)).Value = eventtime
Range(CStr("c" & lngS)).Value = error_code
lngS = lngS + 1
End If
DoEvents
Loop
Close #1
Next
End Sub