none
enforcing a watermark to word documents RRS feed

  • Question

  • hey guys,

    i want to develop an add-in to enforce a watermark for every word 2010 document, i've been searching the web for a while and i didn't find anything

    Tuesday, May 10, 2011 11:38 AM

Answers

  • Hi Samurai,

    I don’t write in C# so I took Paul’s VBA code and converted it to VS2010 VB and created a test document project. It looked like this and it ran perfectly.

    Imports Office = Microsoft.Office.Core

    Public Class ThisDocument

     

        Private Sub ThisDocument_Startup() Handles Me.Startup

            Dim Scn As Word.Section, HdFt As Word.HeaderFooter, Shp As Word.Shape

     

            With Application.ActiveDocument

                For Each Scn In .Sections

                    For Each HdFt In Scn.Headers

                        Shp = HdFt.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect2, "Zu el Fakar", "Tahoma", 10, False, False, 0, 0)

                        With Shp

                            .Line.Visible = False

                            With .TextEffect

                                .NormalizedHeight = False

                                .FontItalic = False

                                .FontBold = True

                            End With

                            With .Fill

                                .Visible = True

                                .Solid()

                                'Light Gray = RGB(192, 192, 192) = 12632256

                                .ForeColor.RGB = 12632256

                                .Transparency = 0.5

                            End With

                            .Rotation = 315

                            .LockAspectRatio = True

                            .Height = Application.InchesToPoints(1.96)

                            .Width = Application.InchesToPoints(7.2)

                            With .WrapFormat

                                .AllowOverlap = True

                                .Side = Word.WdWrapType.wdWrapNone

                                .Type = 3

                            End With

                            .RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin

                            .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin

                            .Left = Word.WdShapePosition.wdShapeCenter

                            .Top = Word.WdShapePosition.wdShapeCenter

                        End With

                    Next HdFt

                Next Scn

            End With

     

        End Sub

     

    Putting the code through a conversion tool VB Net to C# this is what it came up with.

    Word.Section Scn = default(Word.Section);

    Word.HeaderFooter HdFt = default(Word.HeaderFooter);

    Word.Shape Shp = default(Word.Shape);

     

    var _with1 = Application.ActiveDocument;

    foreach ( Scn in _with1.Sections) {

                    foreach ( HdFt in Scn.Headers) {

                                    Shp = HdFt.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect2, "Zu el Fakar", "Tahoma", 10, false, false, 0, 0);

                                    var _with2 = Shp;

                                    _with2.Line.Visible = false;

                                    var _with3 = _with2.TextEffect;

                                    _with3.NormalizedHeight = false;

                                    _with3.FontItalic = false;

                                    _with3.FontBold = true;

                                    var _with4 = _with2.Fill;

                                    _with4.Visible = true;

                                    _with4.Solid();

                                    //Light Gray = RGB(192, 192, 192) = 12632256

                                    _with4.ForeColor.RGB = 12632256;

                                    _with4.Transparency = 0.5;

                                    _with2.Rotation = 315;

                                    _with2.LockAspectRatio = true;

                                    _with2.Height = Application.InchesToPoints(1.96);

                                    _with2.Width = Application.InchesToPoints(7.2);

                                    var _with5 = _with2.WrapFormat;

                                    _with5.AllowOverlap = true;

                                    _with5.Side = Word.WdWrapType.wdWrapNone;

                                    _with5.Type = 3;

                                    _with2.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;

                                    _with2.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;

                                    _with2.Left = Word.WdShapePosition.wdShapeCenter;

                                    _with2.Top = Word.WdShapePosition.wdShapeCenter;

                    }

    }

     

    Hope this helps

     


    Regards, Rich
    • Marked as answer by SamuraiJack Thursday, May 12, 2011 4:24 PM
    Thursday, May 12, 2011 3:29 PM

All replies

  • Hi SamuraiJack

    Below is VB code to verify if a particular watermark text exists.

        For Each sec In ActiveDocument.Sections

            num = sec.Index

            ActiveDocument.Sections(num).Range.Select

            ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

            For Each shp In Selection.HeaderFooter.Shapes

                Selection.HeaderFooter.Shapes(shp.Name).Select

                If Selection.ShapeRange.TextEffect.Text = "Your Watermark" Then

                    violation = False

                End If

            Next shp

            ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

            If violation = True Then ‘Do Something

        Next sec

     

    Assurance that the document is properly watermarked can occur if you call a routine such as the above in the DocumentBeforePrint, or DocumentBeforeSave, or DocumentOpen open events.

     

    Hope this helps


    Regards, Rich
    Tuesday, May 10, 2011 12:41 PM
  • thanks for the reply,

    but how can i insert a watermark and remove it using add-in

    Tuesday, May 10, 2011 1:11 PM
  • To add a watermark:

        For Each sec In ActiveDocument.Sections

            num = sec.Index

            ActiveDocument.Sections(num).Range.Select

            ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

            Selection.HeaderFooter.Shapes.AddTextEffect(msoTextEffect2, _

                "Your Watermark Name", "Tahoma", 1, False, False, 0, 0).Select

            ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

        Next sec

    To delete a watermark:

            For Each shp In Selection.HeaderFooter.Shapes

                Selection.HeaderFooter.Shapes(shp.Name).Select

                If Selection.ShapeRange.TextEffect.Text = "Your Watermark Text" Then

                    Selection.Delete

                End If

            Next shp

     

    Hope this helps


    Regards, Rich
    Tuesday, May 10, 2011 2:27 PM
  • thanks man that worked but how can i make it like this:

    [URL=http://imageshack.us/photo/my-images/215/watermarkzp.jpg/][IMG]http://img215.imageshack.us/img215/6682/watermarkzp.jpg[/IMG][/URL]

    Tuesday, May 10, 2011 3:18 PM
  • I think this should do it.

        For Each sec In ActiveDocument.Sections

            num = sec.Index

            ActiveDocument.Sections(num).Range.Select

            ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

            Selection.HeaderFooter.Shapes.AddTextEffect(msoTextEffect2, _

                "Microsoft Word", "Tahoma", 1, False, False, 0, 0).Select

            Selection.ShapeRange.TextEffect.NormalizedHeight = False

            Selection.ShapeRange.TextEffect.FontItalic = False

            Selection.ShapeRange.TextEffect.FontBold = True

            Selection.ShapeRange.Line.Visible = False

            Selection.ShapeRange.Fill.Visible = True

            Selection.ShapeRange.Fill.Solid

            Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)

            Selection.ShapeRange.Fill.Transparency = 0.5

            Selection.ShapeRange.Rotation = 315

            Selection.ShapeRange.LockAspectRatio = True

            Selection.ShapeRange.Height = InchesToPoints(1.96)

            Selection.ShapeRange.Width = InchesToPoints(7.2)

            Selection.ShapeRange.WrapFormat.AllowOverlap = True

            Selection.ShapeRange.WrapFormat.Side = wdWrapNone

            Selection.ShapeRange.WrapFormat.Type = 3

            Selection.ShapeRange.RelativeHorizontalPosition = _

                wdRelativeVerticalPositionMargin

            Selection.ShapeRange.RelativeVerticalPosition = _

                wdRelativeVerticalPositionMargin

            Selection.ShapeRange.Left = wdShapeCenter

            Selection.ShapeRange.Top = wdShapeCenter

            ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

        Next sec

     


    Regards, Rich
    Tuesday, May 10, 2011 3:31 PM
  • i wrote it and took lots of time to convert to C# but i had an error at this line:

    "Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.NormalizedHeight = Office.MsoTriState.msoFalse;"

    the error said: "Wrong drawing object type for this command"

    here is the whole functioin:

     

    private void WaterMark()

            {

                foreach(Word.Section sec in Application.ActiveDocument.Sections)

                {

                    int num = sec.Index;

                    Application.ActiveDocument.Sections[num].Range.Select();

                    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;

                    Application.ActiveDocument.ActiveWindow.Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect10,

                        "Zu el Fakar", "Tahoma", 10, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,

                        0, 0).Select();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.NormalizedHeight = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.FontItalic = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.FontBold = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Line.Visible = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Visible = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Solid();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.ForeColor.RGB = System.Drawing.Color.LightGray.ToArgb();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Transparency = 0.5f;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Rotation = 315;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.LockAspectRatio = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Height = Application.ActiveDocument.Application.InchesToPoints(1.96f);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Width = Application.ActiveDocument.Application.InchesToPoints(7.2f);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.AllowOverlap = Convert.ToInt32(true);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.Side = Word.WdWrapSideType.wdWrapBoth;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.Type = Word.WdWrapType.wdWrapInline;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition

                        .wdRelativeHorizontalPositionMargin;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.

                        wdRelativeVerticalPositionMargin;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Left = (float)Word.WdShapePosition.wdShapeCenter;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Top = (float)Word.WdShapePosition.wdShapeCenter;

                    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;

                }

            }

    Update:

    i tried commenting the line and the same error popped on the one after it


    Tuesday, May 10, 2011 4:18 PM
  • You might try substituting with this:

     Application.ActiveDocument.ActiveWindow.Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1910882829,

    Instead of using the msoTextEffect10 drawing.

     


    Regards, Rich
    Tuesday, May 10, 2011 6:37 PM
  • it showed that error The name 'PowerPlusWaterMarkObject1910882829' does not exist in the current context

    it worked fine at first when it was just at the header of the document
    Tuesday, May 10, 2011 9:51 PM
  • When it ran fine, what was the name of the object?

    Looking back at the code I orginally sent, the name was msoTextEffect2. When you sent the function's code that you translated you had it listed as msoTextEffect10. 

    Comment out the code, which is trying to format the shaperange and see if the watermark gets added to the header. All the other code is trying to do is to format the shape so that it is larger, bold, placed on an angle, etc.


    Regards, Rich
    Tuesday, May 10, 2011 10:12 PM
  • firstly thanks for helping i know i've been very tiring,

    secondly i don't want the watermark at the header i want it to fill the whole document as i posted in a previous picture

     

    http://imageshack.us/photo/my-images/215/watermarkzp.jpg

    Wednesday, May 11, 2011 6:24 PM
  • Hi Samurai,

    I understand that you don't want it in the header, I'm just trying to figure out what part of the code is working and then what part is not working.

    So if you could post the code that does place the watermark in the header, then we can figure out how to get the watermark properly formatted.


    Regards, Rich
    Wednesday, May 11, 2011 6:50 PM
  • this is the part that is working:

    foreach(Word.Section sec in Application.ActiveDocument.Sections)

                {

                    int num = sec.Index;

                    Application.ActiveDocument.Sections[num].Range.Select();

                    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;

                    Application.ActiveDocument.ActiveWindow.Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect

                        .msoTextEffect2, "Zu el Fakar", "Tahoma", 10, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,

                        0, 0).Select();

    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;

        }

    and this is the whole code: with error message (Wrong drawing object type for this command)

    foreach(Word.Section sec in Application.ActiveDocument.Sections)

                {

                    int num = sec.Index;

                    Application.ActiveDocument.Sections[num].Range.Select();

                    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;

                    Application.ActiveDocument.ActiveWindow.Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect

                        .msoTextEffect2, "Zu el Fakar", "Tahoma", 10, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,

                        0, 0).Select();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.NormalizedHeight = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.FontItalic = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.TextEffect.FontBold = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Line.Visible = Office.MsoTriState.msoFalse;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Visible = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Solid();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.ForeColor.RGB = System.Drawing.Color.LightGray.ToArgb();

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Fill.Transparency = 0.5f;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Rotation = 315;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.LockAspectRatio = Office.MsoTriState.msoCTrue;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Height = Application.ActiveDocument.Application.InchesToPoints(1.96f);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Width = Application.ActiveDocument.Application.InchesToPoints(7.2f);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.AllowOverlap = Convert.ToInt32(true);

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.Side = Word.WdWrapSideType.wdWrapBoth;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.WrapFormat.Type = Word.WdWrapType.wdWrapInline;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition

                        .wdRelativeHorizontalPositionMargin;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.

                        wdRelativeVerticalPositionMargin;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Left = (float)Word.WdShapePosition.wdShapeCenter;

                    Application.ActiveDocument.ActiveWindow.Selection.ShapeRange.Top = (float)Word.WdShapePosition.wdShapeCenter;

                    Application.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;

                }

    Wednesday, May 11, 2011 9:06 PM
  • Hi Samurai,

    The code could be made much simpler and more efficient. Here's a vba rendition:

    Sub Demo()
    Dim Scn As Word.Section, HdFt As Word.HeaderFooter, Shp As Word.Shape
    With Word.ActiveDocument
      For Each Scn In .Sections
        For Each HdFt In Scn.Headers
          Set Shp = HdFt.Shapes.AddTextEffect(msoTextEffect2, "Zu el Fakar", "Tahoma", 10, False, False, 0, 0)
          With Shp
            .Line.Visible = False
            With .TextEffect
              .NormalizedHeight = False
              .FontItalic = False
              .FontBold = True
            End With
            With .Fill
              .Visible = True
              .Solid
              'Light Gray = RGB(192, 192, 192) = 12632256
              .ForeColor.RGB = 12632256
              .Transparency = 0.5
            End With
            .Rotation = 315
            .LockAspectRatio = True
            .Height = Word.InchesToPoints(1.96)
            .Width = Word.InchesToPoints(7.2)
            With .WrapFormat
              .AllowOverlap = True
              .Side = Word.wdWrapNone
              .Type = 3
            End With
            .RelativeHorizontalPosition = Word.wdRelativeHorizontalPositionMargin
            .RelativeVerticalPosition = Word.wdRelativeVerticalPositionMargin
            .Left = Word.wdShapeCenter
            .Top = Word.wdShapeCenter
          End With
        Next HdFt
      Next Scn
    End With
    End Sub

    As you will see if you run this from Word, there is no need for the navigation to/from the header. Neither should you need to keep calling 'Application.ActiveDocument' - simply put the lot in a single With ... End With statement. If put many more 'Word' references in than are needed for vba, but that should make it easier for you to convert.

    PS: I've corrected the '.RelativeHorizontalPosition' reference. I originally copied it from Rich's code, only to find later he'd used 'wdRelativeVerticalPositionMargin' instead of 'wdRelativeHorizontalPositionMargin'.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Edited by macropodMVP Thursday, May 12, 2011 1:25 PM Minor code fix.
    Thursday, May 12, 2011 6:51 AM
  • Nice code Paul ... I like it a lot! :-)

    Maybe it will help resolve SamuariJack's issue because it maintains a hard reference to the watermark shape. I don't see anything "technically" wrong with his original code but his error message suggests Word doesn't agree with the formatting command for the object it believes to be referenced.


    Regards, Rich
    Thursday, May 12, 2011 11:47 AM
  • i don't know if this might help resolve the problem 

    but i am using VS2010 and C#

    Thursday, May 12, 2011 2:54 PM
  • Hi Samurai,

    I don’t write in C# so I took Paul’s VBA code and converted it to VS2010 VB and created a test document project. It looked like this and it ran perfectly.

    Imports Office = Microsoft.Office.Core

    Public Class ThisDocument

     

        Private Sub ThisDocument_Startup() Handles Me.Startup

            Dim Scn As Word.Section, HdFt As Word.HeaderFooter, Shp As Word.Shape

     

            With Application.ActiveDocument

                For Each Scn In .Sections

                    For Each HdFt In Scn.Headers

                        Shp = HdFt.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect2, "Zu el Fakar", "Tahoma", 10, False, False, 0, 0)

                        With Shp

                            .Line.Visible = False

                            With .TextEffect

                                .NormalizedHeight = False

                                .FontItalic = False

                                .FontBold = True

                            End With

                            With .Fill

                                .Visible = True

                                .Solid()

                                'Light Gray = RGB(192, 192, 192) = 12632256

                                .ForeColor.RGB = 12632256

                                .Transparency = 0.5

                            End With

                            .Rotation = 315

                            .LockAspectRatio = True

                            .Height = Application.InchesToPoints(1.96)

                            .Width = Application.InchesToPoints(7.2)

                            With .WrapFormat

                                .AllowOverlap = True

                                .Side = Word.WdWrapType.wdWrapNone

                                .Type = 3

                            End With

                            .RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin

                            .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin

                            .Left = Word.WdShapePosition.wdShapeCenter

                            .Top = Word.WdShapePosition.wdShapeCenter

                        End With

                    Next HdFt

                Next Scn

            End With

     

        End Sub

     

    Putting the code through a conversion tool VB Net to C# this is what it came up with.

    Word.Section Scn = default(Word.Section);

    Word.HeaderFooter HdFt = default(Word.HeaderFooter);

    Word.Shape Shp = default(Word.Shape);

     

    var _with1 = Application.ActiveDocument;

    foreach ( Scn in _with1.Sections) {

                    foreach ( HdFt in Scn.Headers) {

                                    Shp = HdFt.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect2, "Zu el Fakar", "Tahoma", 10, false, false, 0, 0);

                                    var _with2 = Shp;

                                    _with2.Line.Visible = false;

                                    var _with3 = _with2.TextEffect;

                                    _with3.NormalizedHeight = false;

                                    _with3.FontItalic = false;

                                    _with3.FontBold = true;

                                    var _with4 = _with2.Fill;

                                    _with4.Visible = true;

                                    _with4.Solid();

                                    //Light Gray = RGB(192, 192, 192) = 12632256

                                    _with4.ForeColor.RGB = 12632256;

                                    _with4.Transparency = 0.5;

                                    _with2.Rotation = 315;

                                    _with2.LockAspectRatio = true;

                                    _with2.Height = Application.InchesToPoints(1.96);

                                    _with2.Width = Application.InchesToPoints(7.2);

                                    var _with5 = _with2.WrapFormat;

                                    _with5.AllowOverlap = true;

                                    _with5.Side = Word.WdWrapType.wdWrapNone;

                                    _with5.Type = 3;

                                    _with2.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;

                                    _with2.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;

                                    _with2.Left = Word.WdShapePosition.wdShapeCenter;

                                    _with2.Top = Word.WdShapePosition.wdShapeCenter;

                    }

    }

     

    Hope this helps

     


    Regards, Rich
    • Marked as answer by SamuraiJack Thursday, May 12, 2011 4:24 PM
    Thursday, May 12, 2011 3:29 PM
  • thanks very much 

    it worked fine

    Thursday, May 12, 2011 4:25 PM
  • Question Paul,

    How do I use your code to achieve the following watermarks on the fly?

    Input box for Watermark "TYPE First Page Watermark" First Page Hdr THEN

    Input box for Watermark "TYPE primary watermark" Primary Hdr THEN

    Input box for Watermark "TYPE Even Page watermark" Even Page Hdr or Ftr THEN

    Input box for Watermark "TYPE Odd Page Watermark" Odd Page Hdr or Ftr - is this possible?

    I can't seem to do this in Word 2010 as it deletes the watermarks.

    I have 2 sets of code that put in a watermark on all pages regardless of

    Different Odd Even

    Different First Page

    both checked in page layout but I need one on the fly for different sections.

    I am confused as to how to put different Watermarks in Different Sections in the right sequence.

    Thank you for any assistance.

     

    Monday, September 12, 2011 6:13 AM
  • Hi Janine,

    The code I posted would take a fair bit of re-working for that. To begin with, it's coded to put a pre-defined shape into every header in every section of the document, whereas you apparently want to be able to user-spcified text string into only the specified header of what I assume will be a specified Section.

    Thus, you'd need to delete both 'For Each' loops and replace them with code to specify the Section to which 'Scn' relates (eg the Section in which the selection point is positioned, or a user-nominated Section #) and which of the possible header types for that Section should be specified for the 'HdFt' variable, which determines which header in that Section the watermark should go in. Error-checking would be required for both, so as to ensure neither an invalid Section # nor an invalid header type for that Section wasn't used, and to deal with protected Sections. For example, if Section 2 has only a primary header, then there's no point trying to put something into the non-existent first-page header for that Section. Similarly, if the document has only three Sections, trying to put something into Section 4 should be prevented. Plus you need something for confirmation as to whether an existing watermark should be replaced (just in case the user's made a mistake). Consideration would also need to be given as to how continuous Section breaks should be handled (eg such as when a user has a mix of columns on the same page).


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Edited by macropodMVP Monday, September 12, 2011 10:44 AM
    Monday, September 12, 2011 10:42 AM