View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_3_] Robert Crandal[_3_] is offline
external usenet poster
 
Posts: 161
Default Extract paragraphs from text file

"GS" wrote:

Const sProfaneWords$ = "word1,word2,word3" '//and so on

Dim vWord, vData, n&
' This assumes the full path and filename is held in 'sFilename'
vData = Split(ReadTextFile(sFilename), vbCrLf)

For Each vWord In Split(sProfaneWords, ",")
For n = LBound(vData) to UBound(vData)
If (InStr(vData(n), vWord) 0) _
Or (InStr(vData(n), "*") 0) Then
vData(n) = "~": Exit For
Next 'n ' ** compile error here ***
Next 'vWord
vData = Filter(vData, "~", False)

WriteTextFile Join(vData, vbCrLf), sFilename


Hi Gary. I tested this code, but I got a compile error that
said "Next without For".

I figured it might be missing an "End If" above that Next n line,
which I was right (, I hope), and the code did produce output,
but.....this was not exactly the desired output. Your code
was only deleting single sentences or lines that contained a
profanity word.

For my purposes, a "paragraph" constitutes the ENTIRE
block of words that occurs between a pair of "*" border
lines. (The only exception is the first paragraph, because
there is no "*" border at the top of the input file)

Is it possible there was another bug in the code that I
missed?