I'm working on a project in excel and I am taking a text file, reading the text file, and trying to remove the stop words from the text file. But I'm getting stuck on removing the stop words in excel VBA. From the research I've seen it's possible in Java and PHP but I haven't been able to find one specifically to excel VBA. Is there a function that will remove stop words in excel VBA?
Asked
Active
Viewed 1,676 times
1
-
There is no existing function, but if you have a list of stop words then you can use regexp in a loop to do this. http://stackoverflow.com/questions/5883725/replace-variable-string-in-vba – Tim Williams Feb 26 '13 at 19:59
-
1For my ignorance, what is "stop words"? – glh Feb 27 '13 at 12:13
1 Answers
0
Const InputTxtFile As String = "C:\Temp\InTxt.txt"
Const OutputTxtFile As String = "C:\Temp\OutTxt.txt"
Const ListOfStopWords As String = ";CAT;DOG;FOX;"
Sub main()
Dim DataLine As String
Dim strTempLine As String
Open InputTxtFile For Input As #1 'Or FreeFile()
Open OutputTxtFile For Append As #2
While Not EOF(1)
Line Input #1, DataLine
Dim LineTab() As String
LineTab = Split(DataLine, " ") 'Split readed line on space
If UBound(LineTab) > 0 Then
For i = 0 To UBound(LineTab)
If (InStr(ListOfStopWords, ";" + LineTab(i) + ";") = 0) Then 'Look if not in Stop Words list
strTempLine = strTempLine + LineTab(i) + " "
End If
Next
Print #2, strTempLine 'Print to output file
strTempLine = ""
End If
Wend
Close #1
Close #2
End Sub

Community
- 1
- 1

Hugues Paquet Blanchette
- 612
- 3
- 11
- 24