Limiting the Print Button

D

Drufazz

I work in a centre for people with disabilities and we have a problem
with students pressing the print button many multiples of times when
they go to do a print.

I did post a message a while back asking for any VBA that might be
able to limit printing, the only suggestion I got was to replace the
print button with the print dialog. This didn't really work and only
slowed it down a bit :)

I've been doing a bit of a search and come up with the following:


Public Sub FilePrint()

With Dialogs(wdDialogFilePrint)
If .Display = -1 Then
If .NumCopies > 1 Then
MsgBox "You cannot print more than 1 copy."
Else
.Execute
End If
End If
End With

End Sub


Unfortunately this only allows limiting of the number of copies :(

What I really need is some way of making the print button only work
once in say, 30 seconds or so...... enough time for the students to
see that something is coming out of the printer.

Is there any way in VBA that I could put a timer of sorts on the print
button ?

Cheers,
 
H

Helmut Weber

Answered in

word.vba.general

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

macropod

Hi Drufazz,

To prevent reprinting within a specified timeframe, you could test the
document's internal PRINTDATE value, which is accurate to the minute at
least (it may have higher internal resolution, but minute-level is all you
get via a PRINTDATE field). If you compare that date & time against the
current date & time, via your FilePrint sub, you can at least prevent
reprinting until the next minute ticks over - giving anywhere from 0-60
seconds enforced delay.

Alternatively, you could add the print date & time to the document's custom
properties, with accuracy to the second, and test that before allowing
printing to proceed after whatever interval you choose.

Cheers
 
S

skatonni

See if this is any better. Word will appear unresponsive during the delay.

Public Sub FilePrint()

With Dialogs(wdDialogFilePrint)
If .Display = -1 Then
If .NumCopies > 1 Then
MsgBox "You cannot print more than 1 copy."
Else
.Execute
uDelay (30)
End If
End If
End With

End Sub


Sub uDelay(uSeconds)

Dim startTime As Date
startTime = Now()
Do Until Now() > startTime + TimeSerial(0, 0, uSeconds)
Loop

End Sub
 
M

macropod

Hi skatonni,

That tends to stall Word completely, not just make it unresponsive, till the
30 seconds has passed.

A better approach might be:

Option Explicit
Dim startTime As Date

Public Sub FilePrint()
With Dialogs(wdDialogFilePrint)
If .Display = -1 Then
If .NumCopies > 1 Then MsgBox "You cannot print more than 1 copy."
If Now() > startTime + TimeSerial(0, 0, 30) Then
'.Execute
startTime = Now()
Else
MsgBox "You cannot print now. Please try again later"
End If
End If
End With
End Sub

A couple of other points to note:
1. Unless added to the document template, the code only acts on the document
the macro is attached to.
2. If the code is attached to the template, it's then liable to prevent
immediate printing from a second document that hasn't yet been printed,
which may or may not be desirable. That's why I suggested using/adding the
print time value to the printed document, so that the timing could be made
document-specific.
3. You'd also need to trap printing via the printer icon on the toolbar to
be really effective.

Cheers
 
M

macropod

Oops, try:

Option Explicit
Dim startTime As Date

Public Sub FilePrint()
With Dialogs(wdDialogFilePrint)
If .Display = -1 Then
If .NumCopies > 1 Then
MsgBox "You cannot print more than 1 copy."
Exit Sub
End If
If Now() > startTime + TimeSerial(0, 0, 30) Then
.Execute
startTime = Now()
Else
MsgBox "You cannot print now. Please try again later"
End If
End If
End With
End Sub

Cheers
 

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