Home > How-To Library > Text File Handling
How to Extract each and every word individually from a text file
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** Public Sub ExtractWords(ByVal strFilePath As String, ByVal intHeaderLines As Integer) Dim strTxt As String Dim strLines() As String Dim strWords() As String Dim intCount As Integer Dim iCount As Integer On Error GoTo ExtractWords_Error 'Open the text file Open strFilePath For Input As #1 'load the text file in strTxt variable strTxt = Input(LOF(1), 1) 'close the text file Close #1 'Split the line by crlf strLines = Split(strTxt, vbCrLf) For intCount = LBound(strLines) To UBound(strLines) 'To ignore first 6 header lines If Not intCount < intHeaderLines Then 'Split each line into words strWords = Split(strLines(intCount)) For iCount = LBound(strWords) To UBound(strWords) Debug.Print strWords(iCount) Next iCount End If Next intCount On Error GoTo 0 Exit Sub ExtractWords_Error: If Err.Number <> 0 Then Call MsgBox(Err.Number & " " & Err.Description) Err.Clear End Sub
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.