View Single Post
 
Old 10-26-2023, 07:54 AM
TheBigBoss TheBigBoss is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default Finding watermarks in document

Trying to find custom DRAFT watermarks (inserted in Header) and delete them. Should be simple but this macro totally missbehave, it will always return True at "if" statement, yet it counts 0 shapes and doesn't return oSh.Type or oSh.TextEffect.Text?? Is it because oHF is as HeaderFooter and not Header?

Code:
 
Sub FixHeaderFooter()
    Dim oD As Document, oS As Section, oHF As HeaderFooter, oSh As Shape, _
        tmp As String, r As Range, i As Integer
 Set oD = ActiveDocument
    Debug.Print "FIX HEADER/FOOTER--------------------------------"
For Each oS In oD.Sections
            Debug.Print "Section"
            For Each oHF In oS.Headers
                Debug.Print "Header/footer - " & oHF.Shapes.Count & " shape(s)"
                For Each oSh In oHF
                    Debug.Print "Shape Text - " & oSh.TextEffect.Text
                    Debug.Print "Shape Type - " & oSh.Type
                    If oSh.Type = 13 Then
                        Debug.Print "Do you reach here? Really!?"
                        If oSh.Name Like "Picture*" And oSh.TextEffect.Text = "DRAFT" Then
                            oSh.Delete
                            i = i + 1
                        End If
                    End If
                Next oSh
            Next oHF
        Next oS
        Debug.Print i
Exit Sub
Reply With Quote