Hi all...
I wish to delete any table that occur immediately after a line of text
(paragraph) that is red.
Example:
paragraph 1
table
paragraph 2
table <== DELETE
paragraph 3
table
paragraph 4
table <== DELETE
Note that the red text can appear anywhere (could be any of the four paragraphs) and there is always a table immediately after...
I've tried recording a macro for direction (not pretty)... It seems to work, but it keeps crashing at the last table selection Code 5941 Requested member of the collection does not exist.
[VBA]Sub killTables()
Selection.Find.ClearFormatting
With Selection.Find
.Font.Color = wdColorRed
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select
Selection.Cut
With Selection.Find
.Font.Color = wdColorRed
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select
Selection.Cut
With Selection.Find
.Font.Color = wdColorRed
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select
Selection.Cut
With Selection.Find
.Font.Color = wdColorRed
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select 'crashes here
Selection.Cut
Selection.Find.ClearFormatting
End Sub[/VBA]
Any suggestions... direction.... would be appreciated...
Thanks as always...
J



Reply With Quote
