preventing printing on certain printer

R

red6000

Hi,

I have 5 networked printers.
Is there a way I can use VBA to prevent printing on a certain printer?

ie:

on print
if chosen printer = xyz then
msgbox("this printer is broke")
stop print send
end if


Thanks.
 
J

Jean-Guy Marcil

red6000 was telling us:
red6000 nous racontait que :

You could use something like the following to intercept the user attempts at
printing.
The two subs must be named as they are so that they will kick in whenever a
user
does CTRL-P, File > Print or clicks on the print button on the toolbar.

'_______________________________________
Function boolFunCheckPrinter() As Boolean

Dim strPrinter As String
Const strTarget As String = "Target Printer Name"

strPrinter = Trim$(Left$(ActivePrinter, _
InStr(ActivePrinter, " on ")))

If strPrinter = strTarget Then
MsgBox "You cannot use the """ & strTarget & """ printer.", vbCritical,
"Denied"
boolFunCheckPrinter = False
Else
boolFunCheckPrinter = True
End If

End Function
'_______________________________________

'_______________________________________
Sub FilePrint()

Dim strRange As String
Dim strCopy As String
Dim strPages As String
Dim dlgPrint As Dialog

Set dlgPrint = Dialogs(wdDialogFilePrint)
'-1 = OK button
With dlgPrint
If .Display = -1 Then
'Store user choices from dialog box
strRange = .Range
strPages = .Pages
strCopy = .NumCopies
If boolFunCheckPrinter Then
'Print document using user choices
With Dialogs(wdDialogFilePrint)
.Range = strRange
.Pages = strPages
.NumCopies = strCopy
.Execute
End With
End If
End If
End With

End Sub
'_______________________________________

'_______________________________________
Sub FilePrintDefault()

If boolFunCheckPrinter Then ActiveDocument.PrintOut

End Sub
'_______________________________________

You may want to store more options from the dialog box. Here is the list of
arguments that MSFT claims that can be used.... This is notoriously
under-documented an unreliable...:

Background, AppendPrFile, Range, PrToFileName, From, To, Type, NumCopies,
Pages, Order, PrintToFile, Collate, FileName, Printer, OutputPrinter,
DuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth,
PrintZoomPaperHeight, ZoomPaper


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
R

red6000

fantastic.

I'd come across that last night and had managed to do the FilePrintDefault,
but was struggling with the FilePrint.

I've now been able to achieve exactly what I needed.

Many Thanks.
 

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