I have a text file with name, address, phone and some of unuseful line
of text. I would like to extract only name, address, and phone and put them into 3 column in excel.
My general approach is
1-Open text file and read start a loop to read in one line at a time.
[syntax??]
2-Search for key words(Name, Address, Phone) the imply the desired
string to extract [how do I "if line contains "Name" then...??
Put them into a variable string or array [syntax??] Leading blank space
may cause the error. [syntax?]
3-When all desired data is collected, write them in an excel column.
As you can tell I'm new to VB. Any and all help appreciated.
I'm able to search for Name. Pls point me to direction to grab string after Name which is the string that I'm intersted in import to Excel. Ex: NameTony Lee, capture Tony Lee and import it later into excel. Thk!
I tried your code with different variable name, it returns 0 means nothing found. Wonder what I miss?
Line Input #fileno, StringLine
myFoundString = InStr(1, StringLine, SearchStringName, 1)
If myFoundString Then strName = Mid$(StringLine, myFoundString + 6)
TextBox2.Text = myFoundString
On the other hand my approach slightly different encounter bug at SearchStringName +4. I'm stuck? Pls help!
SearchStringName = "Name"
fileno = FreeFile
'open the file for reading
Open myFileName For Input As #fileno
While Not EOF(fileno)
Line Input #fileno, StringLine
If InStr(1, StringLine, SearchStringName, 1) Then
myFoundString = Mid(StringLine, SearchStringName +4)
TextBox2.Text = myFoundString
End If
Wend
I understand the general ideas of your code and the error I got. Thanks for the input.
Well, the text box displays the following "FoundString = Mid(StringLine, SearchStringName +4)". I quite not sure the use of Mid, Trim and Len all in one.