From: Terry Sycamore on
I receive files containing many lines starting with the word 'Table' and
ending with the string '== =='. These are interspersed with a few lines also
beginning with 'Table' but ending with various different strings. I want to
delete the lines endiing '== ==', leaving only the others.

Each line ends with a paragraph mark (after the strings mentioned above.)

I've tried to do this with the Help available in Word and the advice given
in this discussion group but so far failed. Can anybody help?
--
Terry Sycamore
From: StevenM on
To: Terry,

Sub DeleteParagraphs()
Dim sBegin As String
Dim sEnd As String

sBegin = "Table"
sEnd = "== ==" & vbCr

For Each aPara In ActiveDocument.Paragraphs
If Left(aPara.Range.Text, Len(sBegin)) = sBegin Then
If Right(aPara.Range.Text, Len(sEnd)) = sEnd Then
aPara.Range.Delete
End If
End If
Next aPara
End Sub


"Terry Sycamore" wrote:

> I receive files containing many lines starting with the word 'Table' and
> ending with the string '== =='. These are interspersed with a few lines also
> beginning with 'Table' but ending with various different strings. I want to
> delete the lines endiing '== ==', leaving only the others.
>
> Each line ends with a paragraph mark (after the strings mentioned above.)
>
> I've tried to do this with the Help available in Word and the advice given
> in this discussion group but so far failed. Can anybody help?
> --
> Terry Sycamore
From: Doug Robbins - Word MVP on
This should do it

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="== ==^p", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop) = True
Selection.Paragraphs(1).Range.Delete
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Terry Sycamore" <TerrySycamore(a)discussions.microsoft.com> wrote in message
news:4C23D520-AFC0-4481-8A61-D455BCB13355(a)microsoft.com...
>I receive files containing many lines starting with the word 'Table' and
> ending with the string '== =='. These are interspersed with a few lines
> also
> beginning with 'Table' but ending with various different strings. I want
> to
> delete the lines endiing '== ==', leaving only the others.
>
> Each line ends with a paragraph mark (after the strings mentioned above.)
>
> I've tried to do this with the Help available in Word and the advice given
> in this discussion group but so far failed. Can anybody help?
> --
> Terry Sycamore


From: Terry Sycamore on
Thanks for the reply, Doug, but it doesn't work. Gives a 'compile error' and
the lines
Do While .Execute(Findtext:="== ==^p", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop) = True
are highlighted red.
--
Terry Sycamore


"Doug Robbins - Word MVP" wrote:

> This should do it
>
> Dim myrange As Range
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(Findtext:="== ==^p", Forward:=True,
> MatchWildcards:=False, Wrap:=wdFindStop) = True
> Selection.Paragraphs(1).Range.Delete
> Loop
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Terry Sycamore" <TerrySycamore(a)discussions.microsoft.com> wrote in message
> news:4C23D520-AFC0-4481-8A61-D455BCB13355(a)microsoft.com...
> >I receive files containing many lines starting with the word 'Table' and
> > ending with the string '== =='. These are interspersed with a few lines
> > also
> > beginning with 'Table' but ending with various different strings. I want
> > to
> > delete the lines endiing '== ==', leaving only the others.
> >
> > Each line ends with a paragraph mark (after the strings mentioned above.)
> >
> > I've tried to do this with the Help available in Word and the advice given
> > in this discussion group but so far failed. Can anybody help?
> > --
> > Terry Sycamore
>
>
>
From: Terry Sycamore on
Thanks for the reply, Steven, but it doesn't work as it stands. Stepping
through it, I find the line "If Right(aPara.Range.Text, Len(sEnd)) = sEnd" is
not evaluatiing as true. The previous condition with the word "Table" is and
I've made sure exactly the right string that precedes the paragraph mark is
in the variable, by cutting and pasting it. The string is actually "== ==
". Could it be because it ends with spaces?
--
Terry Sycamore


"StevenM" wrote:

> To: Terry,
>
> Sub DeleteParagraphs()
> Dim sBegin As String
> Dim sEnd As String
>
> sBegin = "Table"
> sEnd = "== ==" & vbCr
>
> For Each aPara In ActiveDocument.Paragraphs
> If Left(aPara.Range.Text, Len(sBegin)) = sBegin Then
> If Right(aPara.Range.Text, Len(sEnd)) = sEnd Then
> aPara.Range.Delete
> End If
> End If
> Next aPara
> End Sub
>
>
> "Terry Sycamore" wrote:
>
> > I receive files containing many lines starting with the word 'Table' and
> > ending with the string '== =='. These are interspersed with a few lines also
> > beginning with 'Table' but ending with various different strings. I want to
> > delete the lines endiing '== ==', leaving only the others.
> >
> > Each line ends with a paragraph mark (after the strings mentioned above.)
> >
> > I've tried to do this with the Help available in Word and the advice given
> > in this discussion group but so far failed. Can anybody help?
> > --
> > Terry Sycamore
 |  Next  |  Last
Pages: 1 2
Prev: Blind print out of pages
Next: Word 2007 Color Scheme