Private Sub AddWatermark(ByVal WatermarkText As String)
Dim Selection As Word.Selection = ThisApplication.Selection
Dim wmShape As Word.Shape
'Select the section
Me.Sections(1).Range.Select()
ActiveWindow.ActivePane.View.SeekView = _
Word.WdSeekView.wdSeekCurrentPageHeader
'Create the watermark shape
wmShape = Selection.HeaderFooter.Shapes.AddTextEffect( _
Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
WatermarkText, "Times New Roman", 1, False, False, 0, 0)
'Set all of the attributes of the watermark
With wmShape
.Select()
.Name = "PowerPlusWaterMarkObject1"
.TextEffect.NormalizedHeight = False
.Line.Visible = False
.Fill.Visible = True
.Fill.Solid()
.Fill.ForeColor.RGB = Word.WdColor.wdColorGray25
.Fill.Transparency = 0.5
.Rotation = 315
.LockAspectRatio = True
.Height = ThisApplication.InchesToPoints(2.82)
.Width = ThisApplication.InchesToPoints(5.64)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = Word.WdWrapSideType.wdWrapBoth
.WrapFormat.Type = 3
.RelativeHorizontalPosition = _
Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
.RelativeVerticalPosition = _
Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
.Left = Word.WdShapePosition.wdShapeCenter
.Top = Word.WdShapePosition.wdShapeCenter
End With
'set focus back to document
ActiveWindow.ActivePane.View.SeekView = _
Word.WdSeekView.wdSeekMainDocument
End Sub
Private Sub DeleteWatermark()
Dim Selection As Word.Selection = ThisApplication.Selection
'Select the section
Me.Sections(1).Range.Select()
ActiveWindow.ActivePane.View.SeekView = _
Word.WdSeekView.wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Delete()
'set focus back to document
ActiveWindow.ActivePane.View.SeekView = _
Word.WdSeekView.wdSeekMainDocument
End Sub
Private Sub AddWM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddWM.Click
Try
AddWatermark("Hello World")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DeleteWM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteWM.Click
Try
DeleteWatermark()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub