I have a txt file log that has user input timestamps. I am writing a code that I can search through the txt file for a word and pull the time stamp associated with that word. The time stamp looks like this
+work=2019-08-30|08:41| [IRP] Diagnose
I would like to be able to input the word (in this case Diagnose) and the program pull the time stamp from the line and put it in cell A1. My current code can find Diagnose if its alone (ie no timestamp) but for some reason doesn't recognize Diagnose in the timestamp line. Here is the code that i have started. I am looking for recommendation on how to be able to type in Diagnose into my search message box and the result in cell A1 is 2019-08-30|08:41| Thanks for any help you can provide
Sub Scan()
Dim stdesfile As String
Dim stdataline As String
stdesfile = Application.GetOpenFilename
Find = InputBox("which word")
Open stdesfile For Input As #1
Do While Not EOF(1)
Input #1, stdataline
If stdataline = Find Then
bFound = True
Exit Do
End If
Loop
If bFound = True Then
MsgBox "Item Found"
Else
MsgBox "Item not found"
End If
Close #1
End Sub
Try below code (assuimg the date format is fixed to be 17 characters length):
Sub Scan()
Dim stdesfile As String
Dim stdataline As String
Dim idx As Long, dt As String
stdesfile = Application.GetOpenFilename
Find = InputBox("which word")
Open stdesfile For Input As #1
Do While Not EOF(1)
Input #1, stdataline
If InStr(1, stdataline, Find) > 0 Then
idx = InStr(1, stdataline, "=")
dt = Mid(stdataline, idx + 1, 17)
bFound = True
Exit Do
End If
Loop
If bFound = True Then
MsgBox "Item Found, date: " + dt
Else
MsgBox "Item not found"
End If
Close #1
End Sub
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加