Morning everyone,
Thought I would give back a bit of code that I have been working on all morning so others won't have to search and hack their way to the answer. The function below adds a centered watermark to all pages of a word document. Main class must import Microsoft.Office.Interop and (I think) System.Runtime.InteropServices.
With a little more work this could also be adapted to watermark photos but will leave that for someone else
Code:Private Function AddWatermark(ByVal pdocument As Word.Document) As Word.Document Dim nShape As Word.Shape For Each section As Word.Section In pdocument.Sections nShape = section.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, "DRAFT", "Rockwell Extra Bold", 90, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0) nShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue nShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse nShape.Fill.Solid() nShape.Rotation = -45 nShape.Fill.ForeColor.RGB = Word.WdColor.wdColorGray20 nShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin nShape.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin nShape.Left = Word.WdShapePosition.wdShapeCenter nShape.Top = Word.WdShapePosition.wdShapeCenter Next Return pdocument End Function





Reply With Quote
