Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 03-03-2018, 09:36 PM
gmayor's Avatar
gmayor gmayor is offline Loop through all shapes in all stories not working Windows 10 Loop through all shapes in all stories not working 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through all shapes in all stories not working Loop through worksheet range to show / hide shapes. wlcdo2 Excel Programming 2 02-22-2017 05:10 PM
Loop through all shapes in all stories not working Can a word doc have 2 continuous 'stories' across multiple pages? Cosmo Word 1 06-19-2014 01:09 PM
While loop not working right Cbrehm Excel Programming 0 05-11-2011 11:05 AM
Loop through all shapes in all stories not working Where did map shapes go? SueK PowerPoint 1 01-20-2011 04:30 AM
Loop through all shapes in all stories not working PPT 2010 - Video Shapes and Effects Not Working stepper PowerPoint 2 01-13-2011 12:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft