2013 Jan 06 3:59 PM
Hi Everyone,
I am trying to print my Excel worksheet to a specific printer like a local one on my machine or to a network printer, but having no luck. Could someone please tell me how I could change my code below to print to specific printers like "Printer1" on my LPT1 port and also to a network printer like "Printer 2" on \\Server2?
Many thanks in advance.
REPORT YTEST_EXCEL09.
INCLUDE OLE2INCL .
DATA: E_APPL TYPE OLE2_OBJECT,
E_WORK TYPE OLE2_OBJECT,
E_SHEET TYPE OLE2_OBJECT.
* Start the application
CREATE OBJECT E_APPL 'EXCEL.APPLICATION'.
SET PROPERTY OF E_APPL 'VISIBLE' = 0.
* Open the file
CALL METHOD OF E_APPL 'WORKBOOKS' = E_WORK.
CALL METHOD OF E_WORK 'OPEN'
EXPORTING
#1 = 'c:\test.xls'.
CALL METHOD OF E_APPL 'ACTIVESHEET' = E_SHEET .
CALL METHOD OF E_SHEET 'PRINTOUT'
EXPORTING
#01 = 1 "From
#02 = 1 "To
#03 = 3. "Copies
* Close the file
CALL METHOD OF E_WORK 'close'.
* Quit the file
CALL METHOD OF E_APPL 'QUIT'.
2013 Jan 06 6:33 PM
Thanks, Raymond. I tried adding the 5th parameter using the syntax below (highlighted in blue), but couldn't get it to work: nothing prints, not even from the system default printer. Any ideas?
CALL METHOD OF E_SHEET 'PRINTOUT'
EXPORTING
#01 = 1 "From
#02 = 1 "To
#03 = 3. "Copies
#05 = 'Printer1 on LPT1:'.
2013 Jan 06 5:03 PM
Use the 5th parameter of method Worksheets.PrintOut it is the printer name, 4th is preview.(ref : Worksheets.PrintOut Method (Excel))
Regards,
Raymond
2013 Jan 06 6:33 PM
Thanks, Raymond. I tried adding the 5th parameter using the syntax below (highlighted in blue), but couldn't get it to work: nothing prints, not even from the system default printer. Any ideas?
CALL METHOD OF E_SHEET 'PRINTOUT'
EXPORTING
#01 = 1 "From
#02 = 1 "To
#03 = 3. "Copies
#05 = 'Printer1 on LPT1:'.
2013 Jan 06 6:44 PM
2013 Jan 06 7:13 PM
2013 Jan 06 7:26 PM
2013 Jan 06 7:57 PM
I took the 05 parameter (printer name) 'Printer1 on LPT1:' form the vb source
2013 Jan 06 8:55 PM
2013 Jan 07 12:49 PM
I figured it out: your initial suggestion of using a 4th parameter worked perfectly. I just had to use a valid value for that parameter. In the end, the final code that worked is as below.
Thanks again for your help!
CALL METHOD OF E_SHEET 'PRINTOUT'
EXPORTING
#01 = 1 "From
#02 = 1 "To
#03 = 3 "Copies
#04 = 0 "Preview
#05 = 'Printer1 on LPT1:'. "ActivePrinter
2013 Jan 07 12:51 PM