none
Sample VBS code for Watermark on Word RRS feed

  • Question

  • Hello!

    Can anybody help me with a visual basic script code for generating a new word document, write some text and print a watermark "NON CONTROLLED COPY". I've looked all around and I haven't found any. I need to generate a .vbs file for this action.

    If this kind of question must not be here, please redirect.

    Thank you!

    Monday, July 15, 2013 1:57 PM

Answers

  • Try this:

    Dim app
    Dim doc
    Dim hdr
    Dim shp
    Set app = CreateObject("Word.Application")
    Set doc = app.Documents.Add
    doc.Content.Text = "This is some text."
    Set hdr = doc.Sections(1).Headers(1)
    Set shp = hdr.Shapes.AddTextEffect(1, "NON CONTROLLED COPY", _
        "Calibri", 1, True, False, 0, 0)
    With shp
        .TextEffect.NormalizedHeight = False
        .Line.Visible = False
        .Fill.Visible = True
        .Fill.Solid
        .Fill.ForeColor.RGB = RGB(192, 192, 192)
        .Fill.Transparency = 0.5
        .Rotation = 315
        .LockAspectRatio = True
        .Height = app.InchesToPoints(1.33)
        .Width = app.InchesToPoints(7.55)
        .WrapFormat.AllowOverlap = True
        .WrapFormat.Side = 3
        .WrapFormat.Type = 3
        .RelativeHorizontalPosition = 0
        .RelativeVerticalPosition = 0
        .Left = -999995
        .Top = -999995
    End With
    app.Dialogs(84).Show
    doc.Close False
    app.Quit


    Regards, Hans Vogelaar

    Monday, July 15, 2013 2:34 PM

All replies

  • Try this:

    Dim app
    Dim doc
    Dim hdr
    Dim shp
    Set app = CreateObject("Word.Application")
    Set doc = app.Documents.Add
    doc.Content.Text = "This is some text."
    Set hdr = doc.Sections(1).Headers(1)
    Set shp = hdr.Shapes.AddTextEffect(1, "NON CONTROLLED COPY", _
        "Calibri", 1, True, False, 0, 0)
    With shp
        .TextEffect.NormalizedHeight = False
        .Line.Visible = False
        .Fill.Visible = True
        .Fill.Solid
        .Fill.ForeColor.RGB = RGB(192, 192, 192)
        .Fill.Transparency = 0.5
        .Rotation = 315
        .LockAspectRatio = True
        .Height = app.InchesToPoints(1.33)
        .Width = app.InchesToPoints(7.55)
        .WrapFormat.AllowOverlap = True
        .WrapFormat.Side = 3
        .WrapFormat.Type = 3
        .RelativeHorizontalPosition = 0
        .RelativeVerticalPosition = 0
        .Left = -999995
        .Top = -999995
    End With
    app.Dialogs(84).Show
    doc.Close False
    app.Quit


    Regards, Hans Vogelaar

    Monday, July 15, 2013 2:34 PM
  • Thank you very much Hans! It was very useful :)

    But now...what if I try to put the same watermark (centered in all pages) on an existing file, which has a header? I tried to modify the given code, but it's being put within the header.

    Thank you in advance!

    Tuesday, July 16, 2013 12:39 AM
  • Do you really need to use VBScript for that? Why not run the code from within Word?

    Regards, Hans Vogelaar

    Sunday, July 21, 2013 12:39 AM
  • Try this:

    Dim app
    Dim doc
    Dim hdr
    Dim shp
    Set app = CreateObject("Word.Application")
    Set doc = app.Documents.Add
    doc.Content.Text = "This is some text."
    Set hdr = doc.Sections(1).Headers(1)
    Set shp = hdr.Shapes.AddTextEffect(1, "NON CONTROLLED COPY", _
        "Calibri", 1, True, False, 0, 0)
    With shp
        .TextEffect.NormalizedHeight = False
        .Line.Visible = False
        .Fill.Visible = True
        .Fill.Solid
        .Fill.ForeColor.RGB = RGB(192, 192, 192)
        .Fill.Transparency = 0.5
        .Rotation = 315
        .LockAspectRatio = True
        .Height = app.InchesToPoints(1.33)
        .Width = app.InchesToPoints(7.55)
        .WrapFormat.AllowOverlap = True
        .WrapFormat.Side = 3
        .WrapFormat.Type = 3
        .RelativeHorizontalPosition = 0
        .RelativeVerticalPosition = 0
        .Left = -999995
        .Top = -999995
    End With
    app.Dialogs(84).Show
    doc.Close False
    app.Quit


    Regards, Hans Vogelaar

    I am use above code , watermark is shown on document but some letters of watermark text are dark and some are  light please explain parameters of Addtexteffect method

    Monday, March 6, 2017 5:16 AM
  • I can't explain that; when I use the code, the letters are a uniform light grey.

    See https://msdn.microsoft.com/en-us/library/office/ff192131.aspx for the syntax of AddTextEffect.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, March 6, 2017 6:56 AM
  • did you know how to apply the watermark in pdf file using vb script?.
    Friday, July 13, 2018 3:22 PM
  • I'm sorry, I don't know how to manipulate a PDF file.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Friday, July 13, 2018 3:48 PM