View Single Post
 
Old 11-12-2020, 07:46 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,989
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg

This is a very interesting example of a recursive function to return a collection. I'm intrigued that it works to build a collection which appears to be recreated from New with each recursion. I'm going to have to study this to work how you did that. I would have expected the collection to be created in the Sub and then passed in to the function for filling.

On a speed front, I would think that looping through all the tables appears to be less efficient than just searching for the text and then checking if it happens to be in a nested table. Would this code not do the same thing without the recursion?
Code:
Sub FlyTheNest()
  Dim aRng As Range
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Text = "XXX text"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    While .Execute
      'aRng.Select    'testing purposes only
      If aRng.Information(wdWithInTable) Then
        If aRng.Tables(1).NestingLevel > 1 Then
          aRng.Rows(1).Delete
        End If
      End If
    Wend
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote