Using Delphi, create a new VCL forms application and drop a TComboBox, a TButton and a TWordApplication. Add the unit Printers to the uses clause. In the FormShow event handler, we will fill the combobox with the available printers:
1 2 3 4 5 | procedure TForm1 . FormShow(Sender: TObject); begin ComboBox1 . Items := Printer . Printers; ComboBox1 . ItemIndex := Printer . PrinterIndex; end ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | procedure TForm1 . Button1Click(Sender: TObject); var ADoc : _Document; begin WordApplication1 . Connect; WordApplication1 . Visible := TRUE ; ADoc := WordApplication1 . Documents . Add(emptyParam, emptyParam, emptyParam, emptyParam); WordApplication1 . Selection . Text := 'Embarcadero Delphi Rocks !' + # 13 + WordApplication1 . ActivePrinter := ComboBox1 . Text; WordApplication1 . PrintOut; WordApplication1 . Disconnect; end ; |
Follow me on Twitter
Follow me on LinkedIn
Follow me on Google+
Visit my website: http://www.overbyte.be
1 comment:
AHWord97.pas is a superb example of how to use word automation.
Even though it was written a long time ago it compiles with relatively little effort and works with every version of word i've tested it on.
http://www.torry.net/quicksearchd.php?String=ahword&Title=Yes
Post a Comment