Jean-Guy
Mon Jun 05 15:38:23 CDT 2006
JAY@OPG was telling us:
JAY@OPG nous racontait que :
> I want to setup a print command button on a template that will allow
> me to print to a certain network printer? For example we have a
> template called green sheet and a printer called wcpy_green I want to
> know if there is a way to have a command button that will print to
> wcpy_green or maybe even set it up so that it will only print to that
> printer.
Two Options.
1)
Set it up so that all documents based on this template use the desired
printer automatically when they are created or opened.
In the "ThisDocument" module:
'_______________________________________
Private Const varUserPrinterName As String = "Printer"
Private Const varGreenPrinterName As String = "wcpy_green"
'_______________________________________
Private Sub Document_Close()
Application.ActivePrinter = _
ActiveDocument.Variables(varUserPrinterName).Value
End Sub
'_______________________________________
'_______________________________________
Private Sub Document_New()
ThisDocument.SetPrinter
End Sub
'_______________________________________
'_______________________________________
Private Sub Document_Open()
ThisDocument.SetPrinter
End Sub
'_______________________________________
'_______________________________________
Sub SetPrinter()
ActiveDocument.Variables(varUserPrinterName).Value = _
Application.ActivePrinter
Application.ActivePrinter = varGreenPrinterName
End Sub
'_______________________________________
This printer will also be set if other documents are opened after the target
documents has been opened, but not closed.
2)
Intercept the native print commands
In a standard module:
'_______________________________________
Private Const varUserPrinterName As String = "Printer"
Private Const varGreenPrinterName As String = "wcpy_green"
'_______________________________________
Sub FilePrint()
'To intercept CTRL-P or File > Print
MyModule.SetNewPrinter
Dialogs(wdDialogFilePrint).Show
Application.ActivePrinter = _
ActiveDocument.Variables(varUserPrinterName).Value
End Sub
'_______________________________________
'_______________________________________
Sub FilePrintDefault()
'To intercept the print button on the toolbar
MyModule.SetNewPrinter
ActiveDocument.PrintOut
Application.ActivePrinter = _
ActiveDocument.Variables(varUserPrinterName).Value
End Sub
'_______________________________________
'_______________________________________
Private Sub SetNewPrinter()
ActiveDocument.Variables(varUserPrinterName).Value = _
Application.ActivePrinter
Application.ActivePrinter = varGreenPrinterName
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org