I am trying to delete everything within a range. Currently I am
mostly concerned about text and tables, but will eventually need to
include drawing objects and other such items. I can delete the text
by setting the Range.Text property to the empty string, but how can I
remove the tables. If I use the Range.Tables property, I get the
tables inside the range in most situations, but if the range is inside
of a table I get the outer table, resulting in me deleting much more
than I want to. Can someone please help me with a method to delete
everything from within a range, or at least delete all tables within a
range, without deleting parent tables of a range.

Re: Delete everything within a range by Jean-Guy

Jean-Guy
Tue May 22 15:10:26 CDT 2007

jj was telling us:
jj nous racontait que :

> I am trying to delete everything within a range. Currently I am
> mostly concerned about text and tables, but will eventually need to
> include drawing objects and other such items. I can delete the text
> by setting the Range.Text property to the empty string, but how can I
> remove the tables. If I use the Range.Tables property, I get the
> tables inside the range in most situations, but if the range is inside
> of a table I get the outer table, resulting in me deleting much more
> than I want to. Can someone please help me with a method to delete
> everything from within a range, or at least delete all tables within a
> range, without deleting parent tables of a range.

Have you read my reply to your other post concerning this exact same
question (posted about three hours ago)?

If not, here it is again:

<Quote>
Don't replace the range by something else, just plain delete it.
For example, on my machine, the following code deletes everything in the
rage:

'_______________________________________
Sub DelRange()

Dim rgeDelete As Range

Set rgeDelete = ActiveDocument.Bookmarks("Test").Range

rgeDelete.Delete

End Sub
'_______________________________________

The only problem is if the range is within a table, in which case it deletes
the text, but not the actual rows.
So you would need code to see if Range.Start and Range.End are inside the
same table, if so, delete the rows concerned by the range

Assuming you have already run some code to see whether this code is
necessary, use something like

'_______________________________________
Dim rgeDelete As Range
Dim rwDel As Row

Set rgeDelete = ActiveDocument.Bookmarks("Test").Range

'Code to test if range within a table

For Each rwDel In rgeDelete.Rows
rwDel.Delete
Next
'_______________________________________

<End Quote>


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org