Deleting text boxes with red line or text

J

JayM

Is it possible to use VBA to delete text boxes in a word document that
have a red line around them (or with red text in)?

If so can you point me in the right direction for the code

Many thanks

JayM
 
G

Graham Mayor

Dim aShape As Shape
Dim oRng As Range
Application.ScreenUpdating = False
With ActiveDocument
For Each aShape In .Shapes
If aShape.Type = msoTextBox Then
With aShape
If .Line.ForeColor = wdColorRed Then
.Delete
ElseIf .TextFrame.HasText Then
Set oRng = .TextFrame.TextRange
If oRng.Font.Color = wdColorRed Then
.Delete
End If
End If
End With
End If
Next aShape
End With
Application.ScreenUpdating = True


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

JayM

Graham

Thanks - that works a treat.

I had tried and wasn't in fact that far off but couldn't see where I was
going wrong.

JayM
 
J

John Doue

Graham said:
Dim aShape As Shape
Dim oRng As Range
Application.ScreenUpdating = False
With ActiveDocument
For Each aShape In .Shapes
If aShape.Type = msoTextBox Then
With aShape
If .Line.ForeColor = wdColorRed Then
.Delete
ElseIf .TextFrame.HasText Then
Set oRng = .TextFrame.TextRange
If oRng.Font.Color = wdColorRed Then
.Delete
End If
End If
End With
End If
Next aShape
End With
Application.ScreenUpdating = True

What if I need to delete text boxes of any color but need to preserve
the text inside?

Thanks
 

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