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.

Re: preventing printing on certain printer by red6000

red6000
Tue Jul 31 14:43:26 CDT 2007

I've found http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116,
but i'm not sure where to start

"red6000" <red1000002001@yahoo.com> wrote in message
news:0001d74d$0$2864$c3e8da3@news.astraweb.com...
> 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.
>



Re: preventing printing on certain printer by Jean-Guy

Jean-Guy
Tue Jul 31 21:33:08 CDT 2007

red6000 was telling us:
red6000 nous racontait que :

> I've found
> http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116, but
> i'm not sure where to start
> "red6000" <red1000002001@yahoo.com> wrote in message
> news:0001d74d$0$2864$c3e8da3@news.astraweb.com...
>> 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.

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
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: preventing printing on certain printer by red6000

red6000
Wed Aug 01 12:07:02 CDT 2007

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.


"Jean-Guy Marcil" <DontEvenTry@NoSpam> wrote in message
news:%23wN1RR%230HHA.484@TK2MSFTNGP06.phx.gbl...
> red6000 was telling us:
> red6000 nous racontait que :
>
>> I've found
>> http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116, but
>> i'm not sure where to start
>> "red6000" <red1000002001@yahoo.com> wrote in message
>> news:0001d74d$0$2864$c3e8da3@news.astraweb.com...
>>> 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.
>
> 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
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>