Board index » delphi » Setting ActivePrinter changes default printer

Setting ActivePrinter changes default printer

Hello,

I have the following code.  It appears to me that the call to set up the
ActivePrinter changes the default printer.  Is that correct and is there a
better way to chose a printer and print a word document.

Thanks

    {Create the OLE object and open up the word document}
    WordDocument := CreateOLEObject( 'Word.Application' );
    WordDocument.Documents.Open( DocumentPath + DocumentName );
    {Now set up the printer.  If we still do not have a printer get the
default}
    if PrinterNo = -1 then
    begin
      {Setting PrinterIndex to -1 gives us the default printer}
      Printer.PrinterIndex := -1 ;
      PrinterNo := Printer.PrinterIndex ;
    end ;

    {Finally check that we have a valid printer, then tell word to use it}
    if (PrinterNo >= 0) and (PrinterNo < Printer.Printers.Count) then
    begin

      WordDocument.ActivePrinter := printer.Printers[PrinterNo];

     {Now print the document}
      WordDocument.PrintOut( EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
                      EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
                      EmptyParam, EmptyParam, EmptyParam);

      {Now wait until word has finished printing}
      while WordDocument.BackgroundPrintingStatus > 0 do Sleep( 100 );

    end ;

    WordDocument.Quit( False ) ;

 

Re:Setting ActivePrinter changes default printer


<<Richard Bibby:
It appears to me that the call to set up the ActivePrinter
changes the default printer.  Is that correct and is there a
better way to chose a printer and print a word document.

Quote

Yes, no, and no, I think. :)

--
Deborah Pate

Re:Setting ActivePrinter changes default printer


Welcome to the eternal nightmare of Word Automation.  You can always try
save it to disk and issuing a shell command.  I think the
command line parameter /o:<printer> will work.

Matthew Greet
--
Windows 98 - still not 32 bit.

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads