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)
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
- Imports Microsoft.Office.Interop.Word
- Imports Microsoft.Office.Interop
- Imports Microsoft.Office.Core
- Imports System.Text
- Imports System.IO
- ...
- ...
- Private Sub AddWatermarkToDocument(ByVal sText As String, ByVal fTextSize As Single)
- Dim logoWatermark As Microsoft.Office.Interop.Word.Shape = Nothing
- Try
- For Each section As Microsoft.Office.Interop.Word.Section In WrdDoc.Sections
- For Each hdr As Microsoft.Office.Interop.Word.HeaderFooter In section.Headers
- If hdr.Exists Then
- hdr.Range.[Select]()
- Dim shHeaders As Microsoft.Office.Interop.Word.Shapes = hdr.Shapes
- '>>>Dim headerApp As Microsoft.Office.Interop.Word.Application = WrdDoc.Sections(1).Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Application
- Dim headerApp As Microsoft.Office.Interop.Word.Application = WrdDoc.Sections(1).Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Application
- 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)
- 'logoWatermark.[Select](Type.Missing)
- logoWatermark.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
- logoWatermark.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
- logoWatermark.Fill.Solid()
- logoWatermark.Fill.BackColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Transparent)
- logoWatermark.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
- logoWatermark.Fill.Transparency = 0F
- logoWatermark.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
- logoWatermark.Line.ForeColor.RGB = CType(Microsoft.Office.Interop.Word.WdColor.wdColorRed, Int32)
- logoWatermark.Top = CSng(300)
- logoWatermark.Left = CSng(50)
- logoWatermark.Rotation = CSng(-45)
- End If
- Next
- Next
- Catch ex As Exception
- Throw New Exception(ex.Message)
- End Try
- End Sub