Word Wasserzeichen per VB.NET einfügen für alle Seiten

  • VB.NET

    Word Wasserzeichen per VB.NET einfügen für alle Seiten

    Hallo,
    in einem VB.Net Programm wird eine Word-Datei erzeugt. Nun soll noch (optional) auf alle Seiten ein Wasserzeichen gedruckt werden.
    Mit folgendem Code kommt es nur auf die 1. Seite.
    Kann mir jemand auf die Sprünge helfen?

    Gruß Bernd

    (habe das schon mal in ein anderes Office-Forum gepostet, da kam leider nichts, sorry)

    VB.NET-Quellcode

    1. Imports Microsoft.Office.Interop.Word
    2. Imports Microsoft.Office.Interop
    3. Imports Microsoft.Office.Core
    4. Imports System.Text
    5. Imports System.IO
    6. ...
    7. ...
    8. Private Sub AddWatermarkToDocument(ByVal sText As String, ByVal fTextSize As Single)
    9. Dim logoWatermark As Microsoft.Office.Interop.Word.Shape = Nothing
    10. Try
    11. For Each section As Microsoft.Office.Interop.Word.Section In WrdDoc.Sections
    12. For Each hdr As Microsoft.Office.Interop.Word.HeaderFooter In section.Headers
    13. If hdr.Exists Then
    14. hdr.Range.[Select]()
    15. Dim shHeaders As Microsoft.Office.Interop.Word.Shapes = hdr.Shapes
    16. '>>>Dim headerApp As Microsoft.Office.Interop.Word.Application = WrdDoc.Sections(1).Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Application
    17. Dim headerApp As Microsoft.Office.Interop.Word.Application = WrdDoc.Sections(1).Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Application
    18. logoWatermark = headerApp.ActiveDocument.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, sText, "Arial", 60, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, Type.Missing)
    19. 'logoWatermark.[Select](Type.Missing)
    20. logoWatermark.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
    21. logoWatermark.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
    22. logoWatermark.Fill.Solid()
    23. logoWatermark.Fill.BackColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Transparent)
    24. logoWatermark.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
    25. logoWatermark.Fill.Transparency = 0F
    26. logoWatermark.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
    27. logoWatermark.Line.ForeColor.RGB = CType(Microsoft.Office.Interop.Word.WdColor.wdColorRed, Int32)
    28. logoWatermark.Top = CSng(300)
    29. logoWatermark.Left = CSng(50)
    30. logoWatermark.Rotation = CSng(-45)
    31. End If
    32. Next
    33. Next
    34. Catch ex As Exception
    35. Throw New Exception(ex.Message)
    36. End Try
    37. End Sub