View Single Post
 
Old 03-03-2018, 09:36 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following, which loops through all the story ranges in the document.

Code:
Sub DraftStampsDelete_25_0303_1525()
Dim oStory As Range
Dim sShape As Shape
Dim strText As String
Dim i As Integer
    For Each oStory In ActiveDocument.StoryRanges
        For i = oStory.ShapeRange.Count To 1 Step -1
            Set sShape = oStory.ShapeRange(i)
            If sShape.TextFrame.HasText Then
                strText = sShape.TextFrame.TextRange.Text
                If UCase(Left(strText, 5)) = "DRAFT" Then sShape.Delete
            End If
        Next i
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For i = oStory.ShapeRange.Count To 1 Step -1
                    Set sShape = oStory.ShapeRange(i)
                    If sShape.TextFrame.HasText Then
                        strText = sShape.TextFrame.TextRange.Text
                        If UCase(Left(strText, 5)) = "DRAFT" Then sShape.Delete
                    End If
                Next i
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set sShape = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote