PDA

View Full Version : Solved: Delete All NOT contained in a table



Jinky Julie
10-27-2009, 05:59 AM
Hi again everyone...

I am stuck again... and something so simple...:dunno

I have a short document with tables (there are 5) and paragraphs (there are 11). All of the paragraphs are superfluous.

Is there a way I can delete all of the paragraphs (i.e. single lines of text) and keep the tables in tact?

Thanking you all in advance...

Julie

fumei
10-27-2009, 10:47 AM
"Is there a way I can delete all of the paragraphs (i.e. single lines of text) and keep the tables in tact?"

Yes, and you are correct...it is simple. What have you tried so far?

Important note though. If you remove ALL paragraphs between tables, then Word will consider the remaining content as ONE table. It will merge them.

There is of course a way around this.

A lot depends on if you are properly using Styles.

Jinky Julie
10-27-2009, 11:33 AM
Hi fumei,

You hit the nail on the head... It's now all one big table... obviously NOT what I am looking for...

I've taken some code that you and Macropod helped me with before and tweaked it for this document.

Sub DeleteAllLines()

Dim oPara As Paragraph

With ActiveDocument
For Each oPara In .Paragraphs
With oPara.Range
If .Information(wdWithInTable) = False Then .Delete
End With
Next oPara
End With

End Sub


Cannot keep the spaces... Yet I fight on... As always, looking for a push...

Paragraph styles... still working on that... making progress with Range though...

JJ

macropod
10-27-2009, 06:01 PM
Hi Julie,

Try:
Sub CleanUp()
Dim oPara As Paragraph, rngTxt As Range
With ActiveDocument
For Each oPara In .Paragraphs
With oPara.Range
If .Information(wdWithInTable) = False Then
If Not .Next Is Nothing Then
If .Next.Information(wdWithInTable) = False Then .Delete
End If
If .Characters.Count > 1 Then
If .Next Is Nothing Or .Next.Information(wdWithInTable) = True Then
Set rngTxt = oPara.Range
rngTxt.MoveEnd wdCharacter, -1
rngTxt.Delete
End If
End If
End If
End With
Next
End With
End Sub

Jinky Julie
10-28-2009, 04:29 AM
Macropod...

Worked perfectly!!! Thank you so much!!!

Julie...