there can be multiple watermarks in the header
i have the following vb.net code to delete watermarks.
Whats occuring is; it doesnt delete the specific named watermark. its deleting all/any watermarks.
do i need to define/set my shapes as a specifc range to work with to ensure I delete the correct watermark?
note:
in vba when i step /debug through through the code the correct behaviour occurs and deletes only the specified watermark name.
in vb.net when I run it the result is deletes random/ multiple watermarks in the header
Code: Select all
Dim i As Integer = Nothing
Dim j As Integer = 0
Dim shpname As String = Nothing
Dim HdFt As Microsoft.Office.Interop.Word.HeaderFooter
Dim WordDocument As MSWord.Range = worddoc.Document.Range
'With ActiveDocument
With WordDocument
For i = 1 To .Sections.Count
For Each HdFt In .Sections(i).Headers
With HdFt
For j = HdFt.Shapes.Count To 1 Step -1
shpname = .Shapes(j).AlternativeText
If WATERMARK_STATUS = "CLEAR" Then
.Shapes(j).Delete()
End If
If InStr(shpname, FirstPageWatermark) > 0 Or InStr(shpname, SecondPageWatermark) > 0 Then
'MsgBox(shpname)
.Shapes(j).Delete()
End If
Next j
End With
Next
Next
End With
many thanks
dd