Nested Tables

G

Greg Maxey

Helmut/JGM

The other day the three of us where looking at the problem of drilling down
to "deep" nested tables. Cindy Meister "shoved" me twice in the right
direction and I think I have finally put together some code that will delete
"ALL" empty paragraphs in a document. Cindy, if you are reading, thanks
again!! The code is probably inefficient and ugly, but I haven't been able
to break it in over a half hour of trying. The code as part of the complete
Add in is available here in you care to have a look.

http://gregmaxey.mvps.org/Clean_Up_Text.htm
 
H

Helmut Weber

Hi Greg,

that certainly is an impressive piece of work.
Would need days to test it, but I certainly will.

Just one hint according the listseparator,
always causing trouble for all residents of banana republics,
like me. Check it and use the right, localized (!) one.

As for nested tables, Cindy's approach shows the way,
to access every single cell in every table, nested or not.
Very useful, in case you need it. But do you need it?

Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If Len(oPrg.Range.Text) = 1 Then
oPrg.Range.Delete
End If
Next

Restricted to the mainstory, of course,
and would need user interaction,
if empty oPrg is between tables.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
G

Greg Maxey

Helmut,
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If Len(oPrg.Range.Text) = 1 Then
oPrg.Range.Delete
End If
Next

Yes I considered this. I am using something very similar in the in case of
each cell containing no nested tables:

Else
For Each oPara In oCell.Range.Paragraphs
If oPara.Range.Characters(1).Text = vbCr Then
oPara.Range.Delete
End If
Next
If Len(oCell.Range.Text) > 2 And _
Asc(Right$(oCell.Range.Text, 3)) = 13 Then
oCell.Range.Characters(Len(oCell.Range.Text) - 2).Delete
End If
End If
Next

One thing that your shorted version doesn't handle is the empty space
created when there is an extraneous return at the end of a line of text in a
cell.

The lines of code above are certainly adequate for removing all empty PMs,
but I suppose my real intent is to remove all empty PMs "except" any single
empty PMs separating tables without user interface. That is when the
process became complex and when I started looking for ways to process each
cell.

As you can see, right now I have simply inserted a text flag **** where
deleting and empty PM would have resulted in merging adjacent tables.
Another idea was a message box warning the user of the condition and offer
and option to leave the empty PM as a separator or delete it and merger the
adjacent tables. That quickly became irrating when situation arises many
times in a table. I am studying on providing a user option in setup. If
the user opts to remove all empty PMs with abandonment, then the simple
lines of code above rise to the situation :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top