#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Finding information on a long running document. | Balliol | Word | 8 | 03-04-2016 09:03 AM |
Creating multiple PDF's from word document with different watermarks | mlewis | Word | 1 | 06-03-2014 08:07 AM |
Finding duplicate sentences in a document | seascape | Word VBA | 1 | 02-18-2014 12:31 AM |
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 |