Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

[ ABAP OLE ] How to print with local non-system default printer?

myster
Explorer
0 Kudos

Mentors,

Now I want to use abap ole technology to print an excel sheet. But with the following code, the system default printer is used every time. This is not what I want. I want to set another printer in my code. Is there any way to print with the printer I set up which is a non-system default printer?

GET PROPERTY OF O_EXCEL 'ACTIVEWORKBOOK' = O_TMPL_WORKBOOK.
CALL METHOD OF O_TMPL_WORKBOOK 'PRINTOUT'.
1 ACCEPTED SOLUTION

Rashid_Javed
Contributor

The application object has an Active Printer property. You can set this before sending the printout from your app.

Following is taken from Microsoft online help for active printer property.

The preceding example can be used to discover the proper printer and port naming conventions on your computer for use in the following example.

This example changes the active printer. The colon ":" after the port name is required.

Application.ActivePrinter = "[The name of your printer] on [port]:" 'i.e.

Application.ActivePrinter = "Canon Printer on Ne02:"

RJv
5 REPLIES 5

Rashid_Javed
Contributor

The application object has an Active Printer property. You can set this before sending the printout from your app.

Following is taken from Microsoft online help for active printer property.

The preceding example can be used to discover the proper printer and port naming conventions on your computer for use in the following example.

This example changes the active printer. The colon ":" after the port name is required.

Application.ActivePrinter = "[The name of your printer] on [port]:" 'i.e.

Application.ActivePrinter = "Canon Printer on Ne02:"

RJv

0 Kudos

Hi Rashid.

Thanks for your help very much. By what you said, I can use a printer with a known port number to print. But the problem is I don't know the specific port number of the others. Do I have to test from ne00 port to ne99 port every time to know which port the printer uses? Whether there is an ABAP function or method to get the port number of the printer?

SET PROPERTY OF LO_APPLICATION 'ActivePrinter' = ‘Microsoft XPS Document Writer on Ne04:’.
GET PROPERTY OF LO_APPLICATION 'ACTIVEWORKBOOK' = LO_ACTIVEWORKBOOK.
CALL METHOD OF LO_ACTIVEWORKBOOK 'PRINTOUT'.

Hi Hao

Refer to the link that Sandra has provided. I think this is the best way to get printer ports.

RJv

Hi Rashid.

As you and Sandra suggest, I solved this question by using ABAP loop statement because vba macro is not allowed in my ERP system. Thanks again. I learned a lot.