Reprinting Invoices

L

Lee Kiwiflame

I have a template for invoices and once created, they are saved to a document
management system.

What I want to do is when someone opens the invoice again, and tries to
print the invoice, it automatically inserts a 'COPY' watermark.

I did create the template with a button for users to push if they wanted to
reprint. However, this is dependant on the user pushing the button and they
can still print the original without the 'COPY' watermark if they click File
Print. We don't want them to be able to print it again without the
watermark.

I'm not sure what is the best way to do this. Any ideas would be welcome as
I'm new to VBA and can't think of the best way to do this.
 
G

Greg Maxey

Lee,

Interesting. I believe that this would involve intercepting the various
Print Events and taking actions based on if the document had been ever
printed before. Something like this in your invoice template perhaps:

Dim bRePrint As Boolean

Sub AutoOpen()
On Error GoTo Err_Handler
If ActiveDocument.Variables("Printed").Value = "True" Then
bRePrint = True
Else
bRePrint = False
End If
Exit Sub
Err_Handler:
ActiveDocument.Variables("Printed").Value = "False"
Resume
End Sub

Public Sub FilePrint()
'Intercepts File > Print (Ctrl+P)
If bRePrint Then
InsertCOPYWatermark
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Variables("Printed").Value = "True"
On Error Resume Next
DeleteCopyWaterMark
On Error GoTo 0
Else
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Variables("Printed").Value = "True"
ActiveDocument.Save
AutoOpen
End If
End Sub

Public Sub FilePrintDefault()
'Intercepts Print button
If bRePrint Then
InsertCOPYWatermark
ActiveDocument.Variables("Printed").Value = "True"
ActiveDocument.PrintOut Background:=True
On Error Resume Next
DeleteCopyWaterMark
On Error GoTo 0
Else
ActiveDocument.PrintOut Background:=True
ActiveDocument.Variables("Printed").Value = "True"
ActiveDocument.Save
AutoOpen
End If
End Sub

Public Sub FilePrintPreview()
If bRePrint Then
ActiveDocument.PrintPreview
InsertCOPYWatermark
Else
ActiveDocument.PrintPreview
End If
End Sub

Public Sub ClosePreview()
ActiveDocument.ClosePrintPreview
On Error Resume Next
DeleteCopyWaterMark
On Error GoTo 0
End Sub

Sub InsertCOPYWatermark()
Dim oHdr As HeaderFooter
Dim oShape As Word.Shape
Set oHdr = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
Set oShape = oHdr.Shapes.AddTextEffect(msoTextEffect1, _
"COPY", "Times New Roman", 1, False, False, 0, 0)
With oShape
.Name = "Copy Watermark"
.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 = InchesToPoints(3.05)
.Width = InchesToPoints(6.11)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End Sub

Sub DeleteCopyWaterMark()
Dim oHdr As HeaderFooter
Dim oShape As Word.Shape
Set oHdr = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
Set oShape = oHdr.Shapes(1)
oShape.Delete
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top