I need to read a text file then search for a string and read next line or line right before it.
example text file:
..........
Information for the Online Portal
Primary Contact Full
John Doe
Phone Number
0000000000
Sites Ordering For
..........
I need to search for "Primary Contact Full" and get the name value "John Doe" (which is dynamic)
similarly, I need to search for "E-Mail" to retrieve the vale "[email protected]"
My Sample code to read so far is :
Sub ExtractData()
Dim myFile As String, text As String, textline As String, posLat As Integer, posLong As Integer
myFile = Application.GetOpenFilename()
Open myFile For Input As #iFile
Do Until EOF(1)
Line Input #1, textline
text = text & textline
posLat = InStr(text, "Primary Contact Full")
Loop
Close #1
Range("A1").Value = Mid(text, posLat + 55, 25)
End Sub
I need to be able to read till end of line is encountered.