Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching through text file and displaying results in excel

Status
Not open for further replies.

Newbie311

Programmer
Oct 6, 2003
30
GB
This is a simple query however due to my lack of knowledge on VBA i need HELP! I need to retrieve various values from a text file and display them in an excel spreadsheet, can someone help?
 

sub get text_file()
dim x as string
Open "Drive:\Path\FileName.txt" for input as #1

do unti eof(1)
input #1, x
msgbox(x)
if x=this then
do this
else
do that
end if
loop
close

end sub

 

Alternatively you can open the file into an Excel sheet providing there are less than 65535 lines, use the wizard and record a macro for the syntax, there is probably more on this in help.

As well as the Input as #(Freefile), you can also open "For Append" to add lines and "For Output" to create a new text file.

The #(Freefile) is the handle on the open text files you can have, I think you can open 511 text files at a time.

Regards

Dr B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top