Link to home
Start Free TrialLog in
Avatar of karnso77
karnso77

asked on

Printing an Excel Worksheet from VB

Hi,
This is the problem I am facing.
I have created a worksheet, containing about 10 coluums ans rows. The data for the worksheet is input from a DB Recordset.
Now, I need to print the Active Worksheet to a Printer, in Landscape mode.

I do not have the option to make it the default printer.

I am printing the worksheet using :

CWorkbook.ActiveSheet.PrintOut ActivePrinter:="\\PrintServer\HPLaserJ.2"

Is there any way to print this sheet in Landscape ( by setting some properties in the Worksheet), without making the printer the default and setting the orientation of the printer object ?

I would appretiate any help in this matter.
Thanks,
Kenny.

But i cannot change the orientation.
Avatar of AmericanDogma
AmericanDogma
Flag of United States of America image

The code to change orientation is:

Printing Landscape
Printer.Orientation = 2

OR

Printing Portrait
Printer.Orientation = 1
Here is an article detailing the printer object more indepth

http://www.freevbcode.com/ShowCode.Asp?ID=3646
A little known fact that helps solve this problem easily is that you are allowed to have the same printer twice, (with different default settings)

I suggest you add a new printer (name it HPLaserJ.2 Landscape) and set it to Landscape.

Use this printer in your code

Dabas
Avatar of VBtom
VBtom

Use
CWorkbook.ActiveSheet.pagesetup.orientation = xlLandscape
prior to the .Printout
ASKER CERTIFIED SOLUTION
Avatar of karnso77
karnso77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
karnso77:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Suggest PAQ/Refund.
Asker has supplied his own answer and posted it

Dabas