Add a watermark while printing a Microsoft Word doc w/LotusScript

I have a requirement for two form action buttons:

The first would be for final printing that would print out an OLE Microsoft Word object without the watermark.

The second would be for draft printing that would print out the same object with a DRAFT watermark.

The first button is finished and the second button is finished except for the watermark requirement.

After doing lots of research, I’m not even sure this is possible.

Any help is greatly appreciated.

Thanks,

Jeff Dayton, PCLP, CLI

Subject: Add a watermark while printing a Microsoft Word doc w/LotusScript

Hi Jeffery,

You should be able to get a handle on your Word document and add the watermark using the relevant VBA before printing it. How do your buttons work at the moment? I presume your Word document is embedded in a Notes document somehow.

Emily.

Subject: RE: Add a watermark while printing a Microsoft Word doc w/LotusScript

You’re right Emily.

Here’s the sub that prints the doc currently… I would like to be able to print the watermark on each page of the document.

Sub CallAdobe (doc As NotesDocument)

Dim oldPrinter As String

Dim szFilePath As String

szFilePath = "c:\Documents and Settings\All Users\"	

'*** Get a hold of the embedded object and save it as an MS Word document

Forall o In doc.EmbeddedObjects

	Set handle = o.activate(False)	

	If Not Isempty(handle) Then

		wfile = handle.SaveAs(szFilePath + "Report.doc")

	End If

End Forall	

'*** Using the recently saved copy of the Embedded Object (to MS Word)…

Dim WordObj As Variant

Dim worddoc As Variant

'*** Create Adobe Acrobat object

Set AcroApp = CreateObject("AcroExch.App") 	

'*** Create the word object

Set WordObj = CreateObject("Word.Application")

WordObj.visible = False

'*** Open the Word File

Set worddoc = wordobj.documents.open(szFilePath + "Report.doc",True)

'*** Capture the old default printer set-up

OldPrinter =  WordObj.ActivePrinter	

'*** Set-up the default printer

WordObj.ActivePrinter = "Adobe PDF"

’ WordObj.ActivePrinter.PrinterProperty = PropertyValue

'*** Print to PDF Writer (It must be the default printer)

Call Wordobj.activedocument.PrintOut(0,0,0, "")

'*** Execute a 2 second delay before creating a copy of PDF file. Close Word document.

Sleep (2)

’ Filecopy strPath, szFilePath + "Report - " + doc.PName(0) + “.pdf”

Filecopy "c:\temp\Report.pdf", szFilePath + "Report - " + doc.PName(0) + ".pdf"	

Call Worddoc.Close(False)

'*** Capture the old default printer set-up

WordObj.ActivePrinter = OldPrinter

'*** Close the word object

WordObj.Quit(True)	

Set wordobj = Nothing

End Sub

Subject: Add a watermark while printing a Microsoft Word doc w/LotusScript

I’ve got this code in my toolbox having similarly spent ages trying to do it in the past.

ActiveDocument.Sections(1).Range.Select

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, _

"Do Not Circulate", "Arial", 1, False, False, 0, 0).Select

Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"

Selection.ShapeRange.TextEffect.NormalizedHeight = False

Selection.ShapeRange.Line.Visible = False

Selection.ShapeRange.Fill.Visible = True

Selection.ShapeRange.Fill.Solid

Selection.ShapeRange.Fill.Transparency = 0.5

Selection.ShapeRange.Rotation = 315

Selection.ShapeRange.LockAspectRatio = True	

Selection.ShapeRange.WrapFormat.AllowOverlap = True

Selection.ShapeRange.WrapFormat.Side = wdWrapNone

Selection.ShapeRange.WrapFormat.Type = 3

If I recall correctly it wasn’t actually needed in the end and I don’t know if it actually works - I may just have recorded a keyboard macro and kept the code. Still, it might help.

Subject: RE: Add a watermark while printing a Microsoft Word doc w/LotusScript

I appreciate the code.

I have integrated it as follows… It errors on the line noted with the error:

“Microsoft Word: Command only available in print layout view.”

Sub CallAdobe (doc As NotesDocument)

Print "start Sub CallAdobe"

Dim oldPrinter As String

Dim szFilePath As String

szFilePath = "c:\Documents and Settings\All Users\"	

'*** Get a hold of the embedded object and save it as an MS Word document

Forall o In doc.EmbeddedObjects

	Set handle = o.activate(False)	

	If Not Isempty(handle) Then

		wfile = handle.SaveAs(szFilePath + "Report.doc")

	End If

End Forall	

'*** Using the recently saved copy of the Embedded Object (to MS Word)…

Dim WordObj As Variant

Dim worddoc As Variant

'*** Create Adobe Acrobat object

Set AcroApp = CreateObject("AcroExch.App") 	

'*** Create the word object

Set WordObj = CreateObject("Word.Application")

WordObj.visible = False

'*** Open the Word File

Set worddoc = wordobj.documents.open(szFilePath + "Report.doc",True)



' *** TESTING - set the watermark

WordObj.ActiveDocument.Sections(1).Range.Select

WordObj.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader  ' *** ERRORS ON THIS LINE

Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, _

"DRAFT", "Arial", 1, False, False, 0, 0).Select

Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"	Selection.ShapeRange.TextEffect.NormalizedHeight = False

Selection.ShapeRange.Line.Visible = False

Selection.ShapeRange.Fill.Visible = True

Selection.ShapeRange.Fill.Solid

Selection.ShapeRange.Fill.Transparency = 0.5

Selection.ShapeRange.Rotation = 315

Selection.ShapeRange.LockAspectRatio = True 

Selection.ShapeRange.WrapFormat.AllowOverlap = True

Selection.ShapeRange.WrapFormat.Side = wdWrapNone

Selection.ShapeRange.WrapFormat.Type = 3

'*** Capture the old default printer set-up

OldPrinter =  WordObj.ActivePrinter	

'*** Set-up the default printer

WordObj.ActivePrinter = "Adobe PDF"

’ WordObj.ActivePrinter.PrinterProperty = PropertyValue

'*** Print to PDF Writer (It must be the default printer)

Call Wordobj.activedocument.PrintOut(0,0,0, "")

'*** Execute a 2 second delay before creating a copy of PDF file. Close Word document.

Sleep (2)

’ Filecopy strPath, szFilePath + "Report - " + doc.ProjectName(0) + “.pdf”

Filecopy "c:\temp\Report.pdf", szFilePath + "Report - " + doc.ProjectName(0) + ".pdf"	

Call Worddoc.Close(False)

'*** Capture the old default printer set-up

WordObj.ActivePrinter = OldPrinter

'*** Close the word object

WordObj.Quit(True)	

Set wordobj = Nothing

End Sub

Subject: RE: Add a watermark while printing a Microsoft Word doc w/LotusScript

That’s a pity.

I’ve just been rerunning it, or trying to, and it errors (Object Variable Not Set) on this line:

WordObj.Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, “Do Not Circulate”, “Arial”, 1, False, False, 0, 0).Select

It’s a long time ago but I think the (only) way I figured then to do it was to store a Word document in the Notes database and write it down to the file system then write data to it. Since there was going to be a draft and a final report each with different watermarks I think I formed the view that I’d have to store each in the database with the watermark already there.

What I don’t understand is how, if a macro in Word can do it, and VB can do it, it doesn’t work with LotusScript.

Sorry I can’t be of more help.

Subject: RE: Add a watermark while printing a Microsoft Word doc w/LotusScript

Add WordObj.Documents(1).ActiveWindow.ActivePane.View.Type = 3

before the line

WordObj.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

and you should get rid of the error