Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2023, 07:54 AM
TheBigBoss TheBigBoss is offline Finding watermarks in document Windows 10 Finding watermarks in document Office 2016
Advanced Beginner
Finding watermarks in document
 
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
  #2  
Old 10-27-2023, 02:26 PM
Guessed's Avatar
Guessed Guessed is offline Finding watermarks in document Windows 10 Finding watermarks in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this instead - watermarks inserted by Word's Watermark function won't get found with your code. Your oSh.Type = 13 wouldn't return a standard watermark on my machine. Nor would it match on oSh.Name.
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.Shapes
              Debug.Print "Shape Text - " & oSh.TextEffect.Text
              Debug.Print "Shape Type - " & oSh.Type
              If oSh.Type = msoTextEffect Then      'msoTextEffect = 15
                  Debug.Print "Do you reach here? Really!?"
                  If oSh.TextEffect.Text = "DRAFT" Then
                      oSh.Delete
                      i = i + 1
                  End If
              End If
          Next oSh
      Next oHF
  Next oS
  Debug.Print i
End Sub
If that doesn't work, perhaps you need to post a sample document that shows what your watermarks actually contain.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding watermarks in document Finding information on a long running document. Balliol Word 8 03-04-2016 09:03 AM
Finding watermarks in document Creating multiple PDF's from word document with different watermarks mlewis Word 1 06-03-2014 08:07 AM
Finding watermarks in document Finding duplicate sentences in a document seascape Word VBA 1 02-18-2014 12:31 AM
Finding watermarks in document Finding or searching ^ character in word document shahin3121 Word 2 03-05-2012 06:16 PM
Finding where I last worked on a document. Balliol Word 1 11-24-2010 04:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:07 AM.


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