Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Excel OLE and Worksheet Printing


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Dec 15, 2014 12:48 PM Last Post By: Loren Thompson
Loren Thompson

Posts: 3
Registered: 8/18/03
Excel OLE and Worksheet Printing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 9, 2014 1:49 PM
Can anyone provide a source code example of how to print an Excel worksheet from the TOLEContainer object?
No issues displaying, editing or saving the worksheet document via TOLEContainer itself - just the printing which has me stymied!
I've tried {TOLEContainer}.OLEObject.Application.ActiveWindow.SelectedSheets.PrintOut as suggested on some internet forums.
I receive errors on this statement during runtime, but no source code errors during compile.

Any assistance would be appreciated.

Thanks,
Loren
Mike Shkolnik

Posts: 3
Registered: 9/26/99
Re: Excel OLE and Worksheet Printing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 4:44 AM   in response to: Loren Thompson in response to: Loren Thompson
Hello,

use the PrintOut method for Worksheets:

yourContainer.OLEObject.Application.Worksheets.PrintOut;

With best regards, Mike Shkolnik
E-mail: mshkolnik at scalabium dot com
http://www.scalabium.com
http://www.facebook.com/Scalabium

Loren Thompson wrote:
Can anyone provide a source code example of how to print an Excel worksheet from the TOLEContainer object?
No issues displaying, editing or saving the worksheet document via TOLEContainer itself - just the printing which has me stymied!
I've tried {TOLEContainer}.OLEObject.Application.ActiveWindow.SelectedSheets.PrintOut as suggested on some internet forums.
I receive errors on this statement during runtime, but no source code errors during compile.

Any assistance would be appreciated.

Thanks,
Loren
Loren Thompson

Posts: 3
Registered: 8/18/03
Re: Excel OLE and Worksheet Printing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 7:00 AM   in response to: Mike Shkolnik in response to: Mike Shkolnik
I have tried your suggestion:
yourContainer.OLEObject.Application.Worksheets.PrintOut;
Unfortunately, it throws an Excel OLE Error 800A03EC, which seems to encompass a lot of conditions within OLE Excel.

Does .PrintOut use any explicit parameters? There aren't any parenthesis parameters supposedly used here?

Thanks for replying,
Loren
Loren Thompson

Posts: 3
Registered: 8/18/03
Re: Excel OLE and Worksheet Printing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 15, 2014 12:48 PM   in response to: Loren Thompson in response to: Loren Thompson
I used this version instead which was borrowed from several areas on the web:
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Workbooks.Open(spfn);
ExcelApp.ActiveSheet.PageSetup.Orientation := xlLandscape;
ExcelApp.Worksheets.PrintOut;

This prints out to the OS default printer, not to a printer selected within the controlling application.
So, if it is required to print elsewhere, save the current OS default printer name, set the default printer to the desired printer, then perform the printout.
Remember to reset the OS default printer to its original selection ASAP after the printout is completed.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02